我有一个类型为double
的变量,我需要将其打印出来并保留三位小数,但不能有任何尾随零...
例如,我需要:
2.5 // not 2.500
2 // not 2.000
1.375 // exactly till 3 decimals
2.12 // not 2.120
我尝试使用 DecimalFormatter
,这样做有问题吗?
DecimalFormat myFormatter = new DecimalFormat("0.000");
myFormatter.setDecimalSeparatorAlwaysShown(false);
谢谢。:)