-
Notifications
You must be signed in to change notification settings - Fork 14
Backport unable to parse valid currencies #53
Comments
This is the test showing the bug: @Test
public void testParseDK() {
final Locale.Builder localeBuilder = new Locale.Builder();
localeBuilder.setLanguage("da"); // Danish
MonetaryAmountFormat format = MonetaryFormats
.getAmountFormat(AmountFormatQueryBuilder.of(localeBuilder.build())
.set(CurrencyStyle.CODE)
.build());
MonetaryAmount amountOk = format.parse("123,01 DKK"); // Fails in BP
MonetaryAmount amountKo = format.parse("14 000,12 DKK");
assertEquals(amountOk.getNumber().doubleValueExact(), 123.01); // OK
assertEquals(amountKo.getNumber().doubleValueExact(), 14000.12); // KO
} |
I'm looking into this and here is what I have found so far. First MonetaryAmount tested: "123,01 DKK" I debugged the code and found that the pattern for DKK according to the java.text.DecimalFormat class is: ¤ #,##0.00 So if we test a MonetaryAmount like "DKK 123,01", the test will pass. During the revision I found that there was another issue JavaMoney/jsr354-ri#151 regarding to the Bulgarian formatting pattern so I applied the same fix and it worked: however, I'm not sure if that's the correct way of fixing this kind of issues, what will happen when we find another issue like this? I'm not sure that adding more Regarding to the second MonetaryAmount tested: "14 000,12 DKK" Test is failing with this message: Clearly it is happening due to the whitespace in the number "14 000,12" as stated in #46 Side Note |
Hi @keilw any comment on this? |
Not really, we decided to archive the BP, so it won't be part of the upcoming MR1, do you have a use case where you must continue using Java 7? |
Oh I see. I don't have a use case, I just wanted to contribute. |
We only discussed it with the PMO so far, but here's an announcement: https://groups.io/g/javamoney/message/19 |
Actually for some reason under Java 7 it's "DKK 123,01", not sure, if this is a problem in Moneta, but we won't fix it here any more. |
When testing #46 with other locales also using spaces to separate large numbers, it fails for certain countries/locales the same way, while others show a different problem:
DKK
is a perfectly valid currency code and recognized in the Java 8+ Moneta RI.The text was updated successfully, but these errors were encountered: