We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I managed to adapt the solution for Java 15 and I got the correct output, but the test fails either way 😞 I double checked it with diff and it's 100% the same, including types of spaces (narrow non-breaking space vs. regular space for French formatting). I spent a lot of time investigating on how to get the correct response with NumberFormat, so I share the solution.
The idea is based on using the DecimalFormat derived class that alllows for cusomization of many low-level aspects of the currency rendering through DecimalFormatSymbols substitution – these include the currency symbol and grouping separator that have changed in the locales between Java 8 and Java 15. The second one obviously doesn't work again, so I have to apply the substitution on the final string too, which I'm not happy with, of course. But in general it looks for me like a good answer, with one quirk. What do you think?
Java Currency Formatter
You are viewing a single comment's thread. Return to all comments →
I managed to adapt the solution for Java 15 and I got the correct output, but the test fails either way 😞 I double checked it with diff and it's 100% the same, including types of spaces (narrow non-breaking space vs. regular space for French formatting). I spent a lot of time investigating on how to get the correct response with
NumberFormat, so I share the solution.The idea is based on using the
DecimalFormatderived class that alllows for cusomization of many low-level aspects of the currency rendering throughDecimalFormatSymbolssubstitution – these include the currency symbol and grouping separator that have changed in the locales between Java 8 and Java 15. The second one obviously doesn't work again, so I have to apply the substitution on the final string too, which I'm not happy with, of course. But in general it looks for me like a good answer, with one quirk. What do you think?Here's the code: