JSR 354 - Currency and Money
This JSR focuses on defining interfaces and classes to be used for currencies and monetary amounts. Generally the following areas are defined:
- Core This area defines the classes representing currencies and monetary amounts.
- Conversion This area deals with exchange rates between currencies and provides an API/SPI to perform conversion of monetary amounts from one currency to another.
- Format This area defines APIs/SPIs for formatting and parsing of currencies and monetary amounts, providing support for complex usage scenarios.
It is planned the the JSR will support both SE and ME environments. The reference implementation probably also will include further support for EE/CDI.
Scope and Use Cases
Generally the scope of the JSR is targeting all general application types, e.g.
- Banking and finance
- Insurance and Pension
Nevertheless there are some restrictions (features that are not in scope):
- It is not planned to target low latency such as Algorithmic Trading applications. Nevertheless we will try to keep performance in mind to accomodate such applications.
- Storing a value in multiple currencies (a single value type that is effectively a map of currency to amount, where the amounts are all notionally the same by some form of currency conversion)
- Large exchange rate system (as in a system suitable for trading, such as bid/ask)
- Non-decimal currencies http://en.wikipedia.org/wiki/Non-decimal_currency#Contemporary_non-decimal_currencies
Additionally the following features have been considered as optional:
- Providing static calculation utilities to those developers not using the JSR Money class (eg. those using an unwrapped double/long direcly).
The use cases derived can be found here.
Further Information and Links
External Links and Interesting Resources
- Java Practices -> Representing Money
- Working with Money in Java
- JScience support for monetary quantities and their currencies
- UOMo Business, based on ICU4J and concepts by JScience Economics
- JFire Accounting and JFire Currency Interface for reasons similar to those Stephen outlines below, JFire uses long directly, holding the "minor" amount, formatting it to the necessary representation>
- MoneyDance API for reasons similar to those Stephen outlines, MoneyDance API long directly, holding the "minor" amount. All formatting or currency exchange is done accordingly.
- Joda Money can be referred to as an inspiration for API and design style. it is based on real-world use cases in an e-commerce application for airlines
(must be from a small or US airline, as there is no currency conversion;-)
Note from Joda author Stephen Colebourne: my current company wants estimated amounts at high performance, so uses double directly
- Grails Currencies uses BigDecimal as internal representation, but API only exposes Number in all Money operations like plus(), minus() or similar.
- ICU4J Uses Number for all operations and internal storage in its Money type.
- Why not to use BigDecimal for Money
- M-Pesa-Mobile Money in Africa
- Currency Internationalization (i18n), Multiple Currencies and Foreign Exchange (FX).
- http://en.wikipedia.org/wiki/Japanese_units_of_measurement#Money: Discussion of internationalization of currencies, rounding, grouping and formatting, separators etc]
- http://sourceforge.net/projects/oquote/: It has an interesting Currency and CurrencyAmount structure in it, too. Maybe a good inspiration, and given it is aimed at the UK and International Insurance industry, it sounds like a welcome project to get in touch with. Contains specifications for decimal floating point arithmetic-Werner Keil
- Karatsuba Algorithm for Fast Big Decimal Multiplication