我很惊讶我在寻找如何做到这一点上遇到了很大的困难。在我看来,这应该是非常简单的。也许我找错地方了。
假设我有以下代码:
double amount = 123.45D; //yes, I know that I should be using longs
Locale uk = Locale.UK;
Locale fr = Locale.FR;
Currency euro = Currency.getInstance("EUR");
如何获取 NumberFormat 的实例,让我打印出针对区域设置正确格式化的 123.45 值?即我想要分别针对英国和法国:
€123.45
123,45 €
我不能使用NumberFormat.getCurrencyInstance(Locale)
因为这会将英国格式格式化为英镑 (£)。我正在寻找的是NumberFormat.getCurrencyInstance(Locale, Currency)
,但这似乎并不存在。
有任何想法吗?
Use NumberFormat.setCurrency() http://download.oracle.com/javase/6/docs/api/java/text/NumberFormat.html#setCurrency%28java.util.Currency%29修改用于特定的货币NumberFormat
通过获得NumberFormat.getCurrencyInstance(Locale)
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)