(机器人)的DecimalFormat,使用逗号代替句号,而用&QUOT格式化;###&QUOT。 [英] (android) decimalformat, uses comma in place of fullstop while formatting with "#.##"
本文介绍了(机器人)的DecimalFormat,使用逗号代替句号,而用&QUOT格式化;###&QUOT。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发Android应用程序,我想我的双数字格式###,这是我用下面code完成的。
I am developing an Android app where I want to format my double number to #.##, which I have done using below code.
Double BMI = ((fWeight)/(dHeight*dHeight));
DecimalFormat df = new DecimalFormat("0.00");
String sBMI = df.format(BMI);
而当硬件的语言设置为英语(默认语言)的测试,它工作正常,例如,如果BMI是2497.227216676656,其格式为sBMI 2497.23,但如果语言选择为法国的它编辑成2497,23 。在地方掉血,逗号正在使用的崩溃我的应用程序!
While testing when the language of hardware is set to English(default language), it works fine, for example if BMI is 2497.227216676656 , it formats sBMI to 2497.23 , but if language is selected to French it formats it to 2497,23. In place of DOT, COMMA is being used which is crashing my app!!!
是什么原因?
推荐答案
试试这个:
Double BMI = ((fWeight)/(dHeight*dHeight));
DecimalFormat df = new DecimalFormat("0.00");
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
dfs.setDecimalSeparator('.');
df.setDecimalFormatSymbols(dfs);
String sBMI = df.format(BMI);
这篇关于(机器人)的DecimalFormat,使用逗号代替句号,而用&QUOT格式化;###&QUOT。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文