Java library to represent monetary amounts.

Overview

Joda-Money

Joda-Money provides a library of classes to store amounts of money.

Joda-Money does not provide, nor is it intended to provide, monetary algorithms beyond the most basic and obvious. This is because the requirements for these algorithms vary widely between domains. This library is intended to act as the base layer, providing classes that should be in the JDK.

As a flavour of Joda-Money, here's some example code:

// create a monetary value
Money money = Money.parse("USD 23.87");

// add another amount with safe double conversion
CurrencyUnit usd = CurrencyUnit.of("USD");
money = money.plus(Money.of(usd, 12.43d));

// subtracts an amount in dollars
money = money.minusMajor(2);

// multiplies by 3.5 with rounding
money = money.multipliedBy(3.5d, RoundingMode.DOWN);

// compare two amounts
boolean bigAmount = money.isGreaterThan(dailyWage);

// convert to GBP using a supplied rate
BigDecimal conversionRate = ...;  // obtained from code outside Joda-Money
Money moneyGBP = money.convertedTo(CurrencyUnit.GBP, conversionRate, RoundingMode.HALF_EVEN);

// use a BigMoney for more complex calculations where scale matters
BigMoney moneyCalc = money.toBigMoney();

Users are reminded that this software, like all open source software, is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.

Joda-Money is licensed under the business-friendly Apache 2.0 licence.

Documentation

Various documentation is available:

Releases

Release 1.0.1 is the current release. This release is considered stable and worthy of the 1.x tag. It depends on Java SE 8 or later.

Joda-Money does have a compile-time dependency on Joda-Convert, but this is not required at runtime thanks to the magic of annotations.

Available in the Maven Central repository

Tidelift dependency check

For enterprise

Available as part of the Tidelift Subscription.

Joda and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.

If you want the flexibility of open source and the confidence of commercial-grade software, this is for you.

Learn more

Support

Please use Stack Overflow for general usage questions. GitHub issues and pull requests should be used when you want to help advance the project.

Any donations to support the project are accepted via OpenCollective.

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

Release process

  • Update version (README.md, index.md, changes.xml)
  • Commit and push
  • mvn clean release:clean release:prepare release:perform
  • git fetch
  • Website will be built and released by GitHub Actions
Comments
  • Drop JodaMoney or make it a proper JSR 354 implementation

    Drop JodaMoney or make it a proper JSR 354 implementation

    As JSR 354 EG Member, it would be perfectly legitimate to turn JodaMoney into a proper implementation. When can we expect that, otherwise, there is not a lot of reason to keep the project alive at all.

    Discussion 
    opened by keilw 18
  • Decimal positions for CNY

    Decimal positions for CNY

    We've detected an issue while parsing values on CNY, which contains 2 decimal positions. We've checked the ISO 4217, and it should be 2 decimals. Just for testing purposes, we did the following test: @Test public void testCNY() { String money = "CNY 12.11"; Money value = Money.parse(money); assertNotNull(value); } Which is failing. After checking on the code, I can see the bug is already fixed, but not yet deployed. Any idea when the next release will be? Currently, we are using the 0.9 version.

    Thanks

    Discussion 
    opened by facundofarias 8
  • Add support for former currencies

    Add support for former currencies

    Some currencies are not in use any more, e.g. LVL (https://en.wikipedia.org/wiki/Latvian_lats), LTL (https://en.wikipedia.org/wiki/Lithuanian_litas), however currency rates for passed years contain these currencies, which causes IllegalCurrencyException. Can you come up with additional ConcurrentMap for unused, but still legal currencies?

    RFE Fixed 
    opened by deniss-s 7
  • Support for Bitcoin currency

    Support for Bitcoin currency

    Hi, I hope this is the right place to put this request.

    We use Joda Money as a core library for our XChange project. However, because we support Bitcoin we need to use a custom currency CSV file and this has led to this issue. We were wondering if it would be possible to add BTC to your currencies list like this:

    BTC,-1,-1,
    

    which would enable us to simply use an updated version of your library and not have to bother with specialised initialisation blocks.

    What do you think?

    RFE Fixed 
    opened by gary-rowe 7
  • Joda-Money 1.0 not available on maven central

    Joda-Money 1.0 not available on maven central

    I'm looking here: http://repo1.maven.org/maven2/org/joda/joda-money/

    and the latest I see is 0.9.1. The documentation mentions that 1.0 is the latest stable. Is there a mismatch here?

    Bug Fixed 
    opened by boomesh 6
  • Support currencies with more than 9 decimal places in use

    Support currencies with more than 9 decimal places in use

    With the rise of cryptocurrencies, supporting currencies with greater decimal precision than 9 places would be greatly appreciated.

    The current imposed limit of 9 decimal places works for many, but not all currency divisions. It breaks down when any currency based on Ethereum is used. Ethereum has a standard unit Ether which can be dividled into the Wei. Each Ether can be divided into 10^18 Wei as its smallest denomination.

    Currently I have to register multiple currency units for the Ether at various denominations in order to support the smallest denomination where I need it. This introduces potential error at every conversion in my code adding extra implementation and testing burden. In many cases, in order to avoid potential errors caused by these small divisions I just restrict my users to a max division of 9 decimal places per Ether, but this isn't ideal when tracking the currency.

    I'm willing to attempt a pull request if this is something that joda money is interested in supporting.

    RFE 
    opened by coderjoe 6
  • Incorrect formatting for currencies with 0 decimal digits

    Incorrect formatting for currencies with 0 decimal digits

    Am I doing something wrong or is this a bug, looking at the formatting that occurs at the end of the code below? It looks like the original double value is being repeated after the formatted value in the resulting string. I have the same problem in Chile, which makes me think it may be a general problem with currencies that should be formatted with 0 decimals. Thanks for any insight you can provide!

    @Test
    public void testJodaJapan() {
        CurrencyUnit currency = CurrencyUnit.JPY;
        Money money = Money.of(currency, 12.134d, RoundingMode.HALF_EVEN);
    
        assertEquals(Double.valueOf(12), Double.valueOf(money.getAmount().doubleValue()));
    
        MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_GROUPING;
        MoneyFormatter formatter = new MoneyFormatterBuilder().appendAmount(style).toFormatter()
                .withLocale(Locale.JAPAN);
    
        // BUG Passes - obviously wrong
        assertEquals("1212", formatter.print(money));
        // BUG Fails where it should succeed
        assertEquals("12", formatter.print(money));
    }
    
    Bug Fixed 
    opened by OwensCode 6
  • Javadoc on latest release

    Javadoc on latest release

    When placing the jodamoney library in Netbeans, I get this error when pointing to the javadoc.jar: https://www.dropbox.com/s/z18xyp0h26ueadh/jodamoney%20javadoc.PNG?dl=0.

    Thanks for this great library.

    Discussion Fixed 
    opened by ryguy40 4
  • JPA persistence and joda-money

    JPA persistence and joda-money

    I have now used Joda Money under a couple of persistence providers (Hibernate and EclipseLink). There are varying levels of support for using Money and BigMoney values as entity fields.

    Under Hibernate, there are readily available UserType adapters for Joda Money. Under EclipseLink it's workable but labor intensive - there's no equivalent to Hibernate's UserType stuff, and custom adapters must be written for every entity class that has a Money field.

    Why are all these adapters necessary? Simply put, because immutable value types like Money and BigMoney cannot be properly embedded in JPA entities.

    In order to be easily embedded, objects must:

    • have a default constructor (can be protected)
    • support being initialized by reflection
    • be marked @javax.persistence.Embeddable

    They should also preferably not be marked final, since that keeps the JPA implementation from caching and pooling objects efficiently.

    Since Joda Money is undoubtedly being used in many JPA-based applications, it may be worthwhile to ship a mutable BigMoneyProvider implementation that is amenable to being used as @Embeddable.

    This would mean that applications could implement the JPA spec and not need to worry about third-party libraries to support Joda Money. It would certainly reduce the work involved in swapping out JPA providers.

    Would you accept such an implementation? It would add a compile-time (not runtime) dependency on javax.persistence.Embeddable.

    RFE Fixed 
    opened by gabrielbauman 4
  • Croatia goes EUR

    Croatia goes EUR

    opened by janjaali 3
  • [WIP] Introduce modular testing

    [WIP] Introduce modular testing

    Initial work to switch to JUnit Platform and modular testing.

    Fails at the moment with the following test compilation error:

    [INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ joda-money ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 15 source files to ...\joda-money\target\test-classes
    [INFO] -------------------------------------------------------------
    [ERROR] COMPILATION ERROR :
    [INFO] -------------------------------------------------------------
    [ERROR] ...\joda-money\src\test\java\module-info.java:[20,5]
       error: modules are not supported in -source 8
       use -source 9 or higher to enable modules
    
    • [ ] only activate when running on Java 9+
    • [ ] ensure maven-compiler-plugin:testCompile uses the correct -source settings
    opened by sormuras 3
  • Add .isGreaterThanOrEqual() and isLessThanOrEqual()

    Add .isGreaterThanOrEqual() and isLessThanOrEqual()

    Enhancement request: There's currently isGreaterThan() and isEqual() but no isGreaterThanOrEqual(). Same with LessThan. Those methods would be super convenient!

    RFE 
    opened by stickfigure 3
  • Question: does money formatting support rendering $1 instead of $1.00?

    Question: does money formatting support rendering $1 instead of $1.00?

    Hi, first, thank you for your hard work and contributions to the community.

    Second, is it possible to render Money.of(USD, 1) as "1" instead of "1.00"? I thought withForcedDecimalPoint(false) might do the trick, but it doesn't...

    In short, is there a way to get this test to pass?

    MoneyFormatter moneyFormatter = new MoneyFormatterBuilder()
            .appendAmountLocalized()
            .toFormatter(US);
    assertThat(moneyFormatter.print(Money.of(USD, 1))).isEqualTo("1");
    
    RFE 
    opened by dbaggott 2
  • Currency rounding based on smallest amount possible

    Currency rounding based on smallest amount possible

    In some currencies (e.g. CHF), the smallest spendable amount is not 1, but 5 cents. So rounding a price to 2.73 doesn't not make much sense, because it's not payable. Instead it should be rounded to 2.75.

    Is there any functionality / convenient way without wrapping the whole Money object?

    RFE 
    opened by frne 1
  • Add parser for MoneyFormatterBuilder.appendCurrencySymbolLocalized()

    Add parser for MoneyFormatterBuilder.appendCurrencySymbolLocalized()

    Could a parser be added for MoneyFormatterBuilder.appendCurrencySymbolLocalized()? It would be useful when you get a "$12.34" string as input to pass it directly to joda-money, eg

    MoneyFormatter format = new MoneyFormatterBuilder()
            .appendCurrencySymbolLocalized()
            .appendAmountLocalized()
            .toFormatter();
    Money simpleMoney = format.parse(input)
    

    On 0.9.1 this gives "java.lang.UnsupportedOperationException: MoneyFomatter has not been configured to be able to parse"

    RFE 
    opened by TheLQ 2
  • Support for formatter formats

    Support for formatter formats

    Hi,

    I was looking at the source for Joda Money as it has no way to get a formatter for a specific locale, and noticed a couple commented out functions in MoneyFormatterBuilder taking patterns... Is that something you are working on and is coming up, or something that was abandoned?

    Discussion 
    opened by yarrouye 5
A universal types-preserving Java serialization library that can convert arbitrary Java Objects into JSON and back

A universal types-preserving Java serialization library that can convert arbitrary Java Objects into JSON and back, with a transparent support of any kind of self-references and with a full Java 9 compatibility.

Andrey Mogilev 9 Dec 30, 2021
Java with functions is a small java tools and utils library.

Java with functions is a small java tools and utils library.

null 4 Oct 14, 2022
A modern JSON library for Kotlin and Java.

Moshi Moshi is a modern JSON library for Android and Java. It makes it easy to parse JSON into Java objects: String json = ...; Moshi moshi = new Mos

Square 8.7k Dec 31, 2022
JSON to JSON transformation library written in Java.

Jolt JSON to JSON transformation library written in Java where the "specification" for the transform is itself a JSON document. Useful For Transformin

Bazaarvoice 1.3k Dec 30, 2022
Sawmill is a JSON transformation Java library

Update: June 25, 2020 The 2.0 release of Sawmill introduces a breaking change to the GeoIpProcessor to comply with the updated license of the MaxMind

Logz.io 100 Jan 1, 2023
Genson a fast & modular Java <> Json library

Genson Genson is a complete json <-> java conversion library, providing full databinding, streaming and much more. Gensons main strengths? Easy to use

null 212 Jan 3, 2023
Lean JSON Library for Java, with a compact, elegant API.

mJson is an extremely lightweight Java JSON library with a very concise API. The source code is a single Java file. The license is Apache 2.0. Because

Borislav Iordanov 77 Dec 25, 2022
A modern and lightweight library for working with email addresses in Java

JMail A modern, fast, zero-dependency library for working with email addresses and performing email address validation in Java. Built for Java 8 and u

Rohan Nagar 67 Dec 22, 2022
A wayfast raycast java library.

NOTE: Rayfast is still in development and is not completely stable api-wise. GridCasting likely will not change, however Area3d's may have some improv

EmortalMC 19 Dec 20, 2022
Simple, efficient Excel to POJO library for Java

ZeroCell ZeroCell provides a simple API for loading data from Excel sheets into Plain Old Java Objects (POJOs) using annotations to map columns from a

Credit Data CRB 68 Dec 8, 2022
Elide is a Java library that lets you stand up a GraphQL/JSON-API web service with minimal effort.

Elide Opinionated APIs for web & mobile applications. Read this in other languages: 中文. Table of Contents Background Documentation Install Usage Secur

Yahoo 921 Jan 3, 2023
JSON Library for Java with a focus on providing a clean DSL

JSON Library for Java with a focus on providing a clean DSL

Vaishnav Anil 0 Jul 11, 2022
High performance JVM JSON library

DSL-JSON library Fastest JVM (Java/Android/Scala/Kotlin) JSON library with advanced compile-time databinding support. Compatible with DSL Platform. Ja

New Generation Software Ltd 835 Jan 2, 2023
Screaming fast JSON parsing and serialization library for Android.

#LoganSquare The fastest JSON parsing and serializing library available for Android. Based on Jackson's streaming API, LoganSquare is able to consiste

BlueLine Labs 3.2k Dec 18, 2022
MapNeat is a JVM library written in Kotlin that provides an easy to use DSL (Domain Specific Language) for transforming JSON to JSON, XML to JSON, POJO to JSON in a declarative way.

MapNeat is a JVM library written in Kotlin that provides an easy to use DSL (Domain Specific Language) for transforming JSON to JSON, XML to JSON, POJ

Andrei Ciobanu 59 Sep 17, 2022
Open NFCSense Library

OpenNFCSense API Open-source API of NFCSense for the Processing programming environment (http://processing.org/). Please refer to the following workfl

Rong-Hao Liang 13 Jul 25, 2022
Android processing and secured library for managing SharedPreferences as key-value elements efficiently and structurally.

Memo Android processing and secured library for managing SharedPreferences as key-value elements efficiently and structurally. 1. Depend on our librar

ZeoFlow 18 Jun 30, 2022
A JSON Transmission Protocol and an ORM Library for automatically providing APIs and Docs.

?? 零代码、热更新、全自动 ORM 库,后端接口和文档零代码,前端(客户端) 定制返回 JSON 的数据和结构。 ?? A JSON Transmission Protocol and an ORM Library for automatically providing APIs and Docs.

Tencent 14.4k Dec 31, 2022
Configuration library based on annotation processing

net.cactusthorn.config The Java library with the goal of minimizing the code required to handle application configuration. Motivation The inspiring id

Alexei Khatskevich 7 Jan 8, 2023