Java去掉小数末位的0
java里去掉小数末位的0,一般会用到Bigdecimal 类型,可以调用相关方法去掉小数末位的0
public static void main(String[] args) { BigDecimal value = new BigDecimal("1.4050"); BigDecimal noZeros = value.stripTrailingZeros(); String result = noZeros.toPlainString(); System.out.print(result); }
结果: