Skip to main content
Last updated April 13, 2015 22:27, by keilw
=<img align="right" src=""/> <br/>JSR 354 - Further Implementation Notes<br/><br/><br/> Based on earlier dialogs, the following implementation details produce the requirements for precision and performance: * It was decided that the JSR must be able to support multiple implementations with corresponding interoperability rules. * In concrete a Money class, that will encapsulate BigDecimal and a FastMoney class that includes one long is included in the JSR's reference implementation. * Each amount type declares a MonetaryContext, which contains information on the supported precision and scale. * if using long the number is interpreted as a 10 power -5 minor units. * For all currency arithmetic, calculations are performed according to the full precision of the internal representation. * All calculations are done with maximal precision. Rounding is basically an explicit user operation. * If the internal representation can't be expressed due to an overflow, then it will throw a ArithmeticException. For example, $100/3=33.33333... will throw a ArithmeticException. In early discussions of the JSR the following classes and an internal representations were suggested:<br/> 1. Money - an immutable value object containing a value and a Currency.<br/> 2. Rounding - an immutable object that is included in a Money object on construction.<br/> 3. RoundingAlgorithm - an extendable Enum containing all known rounding algorithms<br/> 4. RoundingException (Checked Exception) - thrown when a calculation produces a value that exceeds the internal representation, and when no rounding is specified to handle that overflow.<br/> 5. Currency (or CurrencyUnit, should we loosely adjust to 310 naming here and avoid ambiguity with java.util.Currency) - an interface, allowing different types of currencies including SPI-style custom currencies, e.g. for Social Networks, Gaming or Online Discount Tickets<br/> 6. CurrencyConverter - a class or interface taking necessary attributes for currency conversion, at least a Money object and target Currency, plus whatever is necessary, e.g. Time/Date (here useful 310 references seem like a good idea;-) In the likely event, CurrencyConverter won't be the only element needed, at least for these a '''sub-package''' like "convert" (see JSF) or "converter" (see JavaFX) seems highly advisable.<br/> 7. ExchangeRate - potentially one or more helper objects to CurrencyConverter in the same package, see above.<br/> 8. format - a sub-package to deal with Money and Currency formatting. While most of the items still apply, some significant changes were made in the course of the JSR. Refer to the [ latest spec] for further details.
Please Confirm