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

Rod*_*dia 6 java formatting android decimalformat

如何根据设备的 Locale.getDefault() 格式化大于 999 的浮点数。

对于十进制格式,目前我正在使用这个:

DecimalFormat decim = new DecimalFormat("#.##");
tv.setText(decim.format(someFloat));
Run Code Online (Sandbox Code Playgroud)

对于千位分隔符:

tv.setText(String.format(Locale.getDefault(), "%,d", someInt));
Run Code Online (Sandbox Code Playgroud)

如果我想显示3.678,66(或3,678.66- 取决于 Locale.getDefault()),如何将两者结合起来?

Rod*_*dia 13

这做到了:

DecimalFormat decim = new DecimalFormat("#,###.##");
tv.setText(decim.format(someFloat));
Run Code Online (Sandbox Code Playgroud)