nscala-money / nscala-money

A Scala wrapper for Joda Money based on the nscala-time wrapper of Joda Time

GitHub

nscala-money

Build Status Maven Central Scaladoc

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

Installation

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.

Usage

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

import com.github.nscala_money.money.Imports._

// For optional Play JSON support
import com.github.nscala_money.money.json.PlayImports._

Money Operations

"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

Documents

Documentation of joda-money will also be helpful.

Acknowledgements

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.

Contributing

Please submit bugs, questions, suggestions, or (ideally) contributions as issues and pull requests on Github.

Maintainers

David R. Bild

License

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.