In France and other countries, the currency symbol is after a monetary amount while in others it is before, plus, the decimal separator is a comma rather than a point (£0.00
vs 0,00 €
).
If I use the following Java code (from memory, may not compile) on my Android device, I can get a 开发者_如何学运维NumberFormat
which formats things correctly:
NumberFormat format = NumberFormat.getCurrencyInstance(Currency.get(Locale.FRANCE));
This NumberFormat
formats to the correct number of decimal places (two in the above examples).
I would like to format to 10 decimal places for a financial app, while keeping the decimal separator and 'symbol side' correct.
I can quite happily build my own format expression - the problem is finding out the information for a particular Locale
or Country
. Is there a way of finding this out at runtime from the Java/Dalvik VMs or am I just going to have to hard code it?
Hard coding it isn't really a problem as I only have about 20 currencies to worry about, but obviously if it can be derived then that is even easier :)
You can use NumberFormat.setMaximumFractionDigits and NumberFormat.setMinimumFractionDigits to control how many decimal places are shown.
精彩评论