Java: formatting currency amounts using small currency symbols

Java provides a good way to format currencies using basic characters depending on a specific locale. For example, if this currency is the US dollar, you can reach $0.35either USD0.35for the US and UK locales, respectively. It is very good.

However, in some cases it is necessary to format the money in another, I would say, a more user-friendly style using small currency symbols. For example, 35¢or 35cinstead of the above examples. Wikipedia also says :

Cent is from 1 cent to 99 cents can be represented as one or two digits, followed by a corresponding reduction (2 ¢, 5 ¢, 75 ¢, 99 ¢)

However, I cannot find a way to format money amounts in this style using the JDK. I already tried to play with DecimalFormatSymbols, but this only allows you to configure the main currency symbol, so it DecimalFormatstill uses the original format, giving something like ¢35what is wrong. In addition, the custom format string for order correction may not be the language / language / agent of the country (intermediate space? Prefix or suffix notation?). Joda Money and its MoneyFormatter do not seem to have this feature either.

Is there a good way to format currency amounts using small currency symbols? Thanks in advance.

PS I'm not sure that the words "major" and "minor" are appropriate here.

+4
source share
1 answer

I honestly believe that the best thing to do here if you really need small currencies is to do your own analysis of the information in the lines. If necessary, you can even make your own money class using different methods that print strings or whatever you want! You will need to evaluate your situation and determine if its user output is really worth it. :)

0
source

All Articles