A Scala wrapper for Joda Money, in the same vein as the nscala-time wrapper for Joda Time. An optional helper for Play JSON is available.
Name | Description | Scaladoc |
---|---|---|
nscala-money |
Pure Scala Wrapper | API |
nscala-money-play-json |
Play JSON Reads/Writes |
API |
Add the following to your sbt build (Scala 2.11.x and Scala 2.12.x):
libraryDependencies += "com.github.nscala-money" %% "nscala-money" % "0.13.0"
To support reading and writing JodaMoney objects using Play JSON 2.6, also add (Scala 2.11.x and Scala 2.12.x):
libraryDependencies += "com.github.nscala-money" %% "nscala-money-play-json" % "0.13.0"
If you want to use previous versions, you can find them here.
This is mostly a convenience wrapper around the Joda Money libraries, adding more pleasant syntax like operators for addition, subtraction, and comparison. Also, most fields usually available as getField
are now simply available as field
, following Scala convention. Some instances of asX
or toX
have also been shortened.
The nscala-money-play-json
helper adds support for Play JSON.
Various Reads
and Writes
for CurrencyUnit
, Money
, and
BigMoney
are provided.
import com.github.nscala_money.money.Imports._
// For optional Play JSON support
import com.github.nscala_money.money.json.PlayImports._
"USD 10.99".toMoney // returns org.joda.money.Money
"USD".toCurrency // returns org.joda.money.CurrencyUnit
"USD 10.99".toMoney + "USD 1.00".toMoney // returns org.joda.money.Money = USD 11.99
Please see Joda Money for a full explanation of key concepts and the API: http://www.joda.org/joda-money
Documentation of joda-money will also be helpful.
This wrapper library is intended to do for Joda Money what
nscala-time
does for Joda Time. The project structure and much of
the boilerplate (including this README) were taken directly from
nscala-time
.
Please submit bugs, questions, suggestions, or (ideally) contributions as issues and pull requests on Github.
David R. Bild
Copyright 2015-2016 David R. Bild
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License from the LICENSE.txt file or at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.