在Textview中显示千位分隔符和十进制格式的数字

问题描述 投票:2回答:2

根据设备的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()),我如何组合两者?

java android formatting decimalformat
2个回答
3
投票

这样就可以了:

DecimalFormat decim = new DecimalFormat("#,###.##");
tv.setText(decim.format(someFloat));

0
投票

你可以试试

NumberFormat.getInstance().format(my number)

格式化为默认语言环境

© www.soinside.com 2019 - 2024. All rights reserved.