jsr354

Customizing a MonetaryAmountFormat using the Moneta (JavaMoney) JSR354 implemenation

和自甴很熟 提交于 2019-12-22 08:24:42
问题 I'm really confused about how to customize a MonetaryAmountFormat using the Moneta JSR-354 implementation. My intention is to be able to parse both 1.23 and $3.45 as MonetaryAmount s. Here is my unit test: @Test public void testString() { Bid bid = new Bid("1.23"); assertEquals(1.23, bid.getValue(), 0.0); System.out.println(bid); bid = new Bid("$3.45"); assertEquals(3.45, bid.getValue(), 0.0); System.out.println(bid); } Here is my class: public final class Bid { private static final

JSR-354 MonetaryAmountFormat not working two way for other currency symbols than $, € or £

妖精的绣舞 提交于 2019-12-12 20:06:20
问题 Here is example code that I'm using with Moneta version 1.1: Locale LANG = Locale.CHINA; // also tried new Locale("pl", "PL"); final MonetaryAmountFormat format = MonetaryFormats.getAmountFormat( AmountFormatQueryBuilder.of(LANG) .set(CurrencyStyle.SYMBOL) .set("pattern", "#,##0.00### ¤") .build() ); final String formatted = format.format(Money.of(new BigDecimal("1234.56"), Monetary.getCurrency(LANG))); System.out.println(formatted); System.out.println(format.parse(formatted).getNumber());

Java's Monetary and Currency Operation - JSR 354

半腔热情 提交于 2019-12-11 07:56:43
问题 I was just curious if anyone knew whether JSR 354 will have an official implementation as part of any future JDK. JDK 11 JavaDocs JSR354 Reference Implementation When I search JDK 11 docs online - it doesn't look like Monetary and MonetaryAmount classes aren't included. But the implementation of JSR 354 exists in Github under jsr354-ri. Does it mean that I can write my own implementation, if I don't want to follow the reference implementation? My purpose is to support additional currencies e

How to format MonetaryAmount with currency symbol?

孤街浪徒 提交于 2019-12-11 01:19:20
问题 Edit: This question is intended to be for formatting within the context of JSR-354. An alternative would be to use java.util.CurrencyFormat . But I want to know how to do it using MonetaryAmountFormat . How do you format a MonetaryAmount using the currency symbol within the context of JSR-354 MonetaryAmountFormat ? I tried to use MonetaryAmountFormat as demonstrated below from two different examples I found on the web. Neither approach worked properly so I pushed my example test cases to