-1 java string-formatting number-formatting decimalformat
我正在尝试格式化数字DecimalFormat.但我希望它格式化一个数字,就像
input: 1234. --> should be formatted to: 1,234.
Run Code Online (Sandbox Code Playgroud)
但我得到1,234.0或1,234.00取决于我的十进制格式规则我需要做什么才能完成这项工作?
应该帮助你的方法是setMinimumFractionDigits和setMaximumFractionDigits.
format.setMinimumFractionDigits(0);
Run Code Online (Sandbox Code Playgroud)
在猜测,可能是你想要的.
要确保始终显示小数分隔符,请使用:DecimalFormat.setDecimalSeparatorAlwaysShown(true)