根据设备的Locale.getDefault(),如何格式化大于999的浮点数。
对于十进制格式,我现在使用这个:
DecimalFormat decim = new DecimalFormat("#.##");
tv.setText(decim.format(someFloat));
并为千分隔符:
tv.setText(String.format(Locale.getDefault(), "%,d", someInt));
如果我想显示3.678,66
(或3,678.66
- 取决于Locale.getDefault()),我如何组合两者?
这样就可以了:
DecimalFormat decim = new DecimalFormat("#,###.##");
tv.setText(decim.format(someFloat));
你可以试试
NumberFormat.getInstance().format(my number)
格式化为默认语言环境