Java Language
화폐와 돈
수색…
맞춤 통화 추가
classpath에 필요한 JAR :
- javax.money:money-api:1.0 (JSR354 화폐 및 통화 API)
- org.javamoney : moneta : 1.0 (참조 구현)
- javax : annotation-api : 1.2. (참조 구현에서 사용되는 공통 주석)
// Let's create non-ISO currency, such as bitcoin
// At first, this will throw UnknownCurrencyException
MonetaryAmount moneys = Money.of(new BigDecimal("0.1"), "BTC");
// This happens because bitcoin is unknown to default currency
// providers
System.out.println(Monetary.isCurrencyAvailable("BTC")); // false
// We will build new currency using CurrencyUnitBuilder provided by org.javamoney.moneta
CurrencyUnit bitcoin = CurrencyUnitBuilder
.of("BTC", "BtcCurrencyProvider") // Set currency code and currency provider name
.setDefaultFractionDigits(2) // Set default fraction digits
.build(true); // Build new currency unit. Here 'true' means
// currency unit is to be registered and
// accessible within default monetary context
// Now BTC is available
System.out.println(Monetary.isCurrencyAvailable("BTC")); // True
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow