????JSR 354??????????μ?Java????API?????????Java 9???????????????????????????????ο?????JavaMoney?????????
?????????????????Java 8?μ????????API?????????????????????????Щ????????????μ?API???÷? ??
??????????????????????λ????????????1淶??????????μ?API??????????
???????????????????????????????????????JDK????????????κ?????????????????е?java.util.Currency????????????ISO 4217?????????????????????й???????????????????JDK??????????????????????????????????????????????????????????
??????????????Maven??????????????????????????????????????òο??????????????
????<dependency>
????<groupId>org.javamoney</groupId>
????<artifactId>moneta</artifactId>
????<version>0.9</version>
????</dependency>
?????淶??????????????javax.money.*?????檔
??????????????????????CurrencyUnit??MonetaryAmount???????
????CurrencyUnit??MonetaryAmount
????CurrencyUnit??????????????е????????????java.util.Currency?????????????????????????????淶???????????java.util.Currency?????????y????CurrencyUnit????????????MonetaryCurrencies???????????
????// ????????????????????λ
????CurrencyUnit euro = MonetaryCurrencies.getCurrency("EUR");
????CurrencyUnit usDollar = MonetaryCurrencies.getCurrency("USD");
????// ???????????????????λ
????CurrencyUnit yen = MonetaryCurrencies.getCurrency(Locale.JAPAN);
????CurrencyUnit canadianDollar = MonetaryCurrencies.getCurrency(Locale.CANADA);
????MontetaryAmount????????????????????????????????CurrencyUnit????MontetaryAmount??CurrencyUnit??????????????????????????CurrencyUnit??MontetaryAmount??????????????????????????
????/ get MonetaryAmount from CurrencyUnit
????CurrencyUnit euro = MonetaryCurrencies.getCurrency("EUR");
????MonetaryAmount fiveEuro = Money.of(5?? euro);
????// get MonetaryAmount from currency code
????MonetaryAmount tenUsDollar = Money.of(10?? "USD");
????// FastMoney is an alternative MonetaryAmount factory that focuses on performance
????MonetaryAmount sevenEuro = FastMoney.of(7?? euro);
????Money??FastMoney??JavaMoney????MonetaryAmount??????????Money??????????????BigDecimal???洢??FastMoney???????????????????long???????洢???????????????FastMoney?????????Money???10??15????????????FastMoney?????С???????????long?????
???????????????Money??FastMoney???????????????????org.javamoney.moneta.*?????棬??????javax.money.*??????????????????????????????????MonetaryAmountFactory?????????MonetaryAmount?????:
????MonetaryAmount specAmount = MonetaryAmounts.getDefaultAmountFactory()
????.setNumber(123.45)
????.setCurrency("USD")
????.create();
?????????????????????λ??????????????????????????MontetaryAmount??????????
????MonetaryAmount oneEuro = Money.of(1?? MonetaryCurrencies.getCurrency("EUR"));
????boolean isEqual = oneEuro.equals(Money.of(1?? "EUR")); // true
????boolean isEqualFast = oneEuro.equals(FastMoney.of(1?? "EUR")); // false
????MonetaryAmount????????????????????????????????????????????
????MonetaryAmount monetaryAmount = Money.of(123.45?? euro);
????CurrencyUnit currency = monetaryAmount.getCurrency();
????NumberValue numberValue = monetaryAmount.getNumber();
????int intValue = numberValue.intValue(); // 123
????double doubleValue = numberValue.doubleValue(); // 123.45
????long fractionDenominator = numberValue.getAmountFractionDenominator(); // 100
????long fractionNumerator = numberValue.getAmountFractionNumerator(); // 45
????int precision = numberValue.getPrecision(); // 5
????// NumberValue extends java.lang.Number.
????// So we assign numberValue to a variable of type Number
????Number number = numberValue;