用错了小数点分隔符格式化货币的Andr​​oid [英] Formatting currency in Android using wrong decimal separator

查看:191
本文介绍了用错了小数点分隔符格式化货币的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一个瑞典用户说我们瑞典的货币用错了小数点分隔符的bug报告。

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

他们说的格式应为1 020,00 KR。当我检查格式对象,它看起来像它具有decimalSeparator,中的符号表,而是一个monetarySeparator的:

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 ":".

有谁知道:其实是正确的,这是否是在Android的/ Java中的漏洞,或任何形式的变通办法

Does anyone know if : is actually correct, whether this is a bug in Android/java, or any sort of workaround?

推荐答案

这就像你的用户说:在瑞典的千位分隔符是空格和小数点分隔符是逗号,和货币符号KR(克朗)。因此,冒号:肯定是不对的。

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.

您可以检查在这里太: http://www.localeplanet.com/java/ SV-SE /

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

什么Java版本是您使用?它运作良好,我的桌面上1.6.0_13

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

- 更新 -

看来,在Android上有一个错误,但你可以去周围的错误使用的DecimalFormatSymbols是这样的:

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);

这将打印在Android上正确的分隔符为好。

This prints the correct separators in Android as well.

这篇关于用错了小数点分隔符格式化货币的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆