更改DecimalFormat语言环境 [英] Change DecimalFormat locale
本文介绍了更改DecimalFormat语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Edittext的addTextChangedListener方法中具有自定义DecimalFormat
,一切正常,但是当我更改语言(语言环境)时,我的addTextChangedListener无法正常工作.
I have custom DecimalFormat
in Edittext's addTextChangedListener method, everything is working perfectly but when I change language (locale) my addTextChangedListener is not working.
double answer = inputDouble * counterToDouble;
DecimalFormat df = new DecimalFormat("##.########");
// df=(DecimalFormat)numberFormat;
df.setRoundingMode(RoundingMode.DOWN);
answer = Double.parseDouble(df.format(answer));
unicoinsAmmount.setText(String.valueOf(df.format(answer)));
我搜索了自己的问题,并找到了NumberFormat
解决方案:
I searched about my problem and found a NumberFormat
solution:
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
但是我不知道如何使用此代码.
but I don't know how I can use this code.
推荐答案
您可以尝试先转换为NumberFormat
,然后将其转换为DecimalFormat
You may try by first converting to NumberFormat
and then Cast it to DecimalFormat
Integer vc = 3210000;
NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
DecimalFormat formatter = (DecimalFormat) nf;
formatter.applyPattern("#,###,###");
String fString = formatter.format(vc);
return convertNumbersToEnglish(fString);
这篇关于更改DecimalFormat语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文