Formatting currency in Android using wrong decimal separator

android, currency, java, localization

Solution

It's like your user says: In Swedish thousand separator is white space " " and decimal separator is comma "," and currency symbol "kr" (Krona). So colon ":" is definitely wrong.

You can check it here too: http://www.localeplanet.com/java/sv-SE/

What Java version are you using? It works well on my desktop 1.6.0_13

-- update --

It seems that on Android there's a bug, but you can go around the bug by using the DecimalFormatSymbols like this:

    DecimalFormat svSE = new DecimalFormat("#,###.00");
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(new Locale("sv", "SE"));
    symbols.setDecimalSeparator(',');
    symbols.setGroupingSeparator(' ');
    svSE.setDecimalFormatSymbols(symbols);

This prints the correct separators in Android as well.

Problem

I got a bug report from a Swedish user saying that our Swedish currency was using the wrong decimal separator. ``` NumberFormat enUS = NumberFormat.getCurrencyInstance(Locale.US); NumberFormat enGB = NumberFormat.getCurrencyInstance(Locale.UK); NumberFormat svSE = NumberFormat.getCurrencyInstance(new Locale("sv", "SE")); double cost = 1020d; String fmt = "en_US: %s en_GB %s sv_SE %s"; String text = String.format(fmt, enUS.format(cost), enGB.format(cost), svSE.format(cost)); Log.e("Format", text); > Format﹕ en_US: $1,020.00 en_GB £1,020.00 sv_SE 1 020:00 kr ``` They say that the format should be "1 020,00 kr". When I inspect the format object, it looks like it has decimalSeparator of "," in the symbols table, but a "monetarySeparator" of ":". Does anyone know if : is actually correct, whether this is a bug in Android/java, or any sort of workaround?

Original source