1.利用正则表达

String s = "123.045600";

if(s.indexOf(".") > 0){

  //正则表达

  s = s.replaceAll("0+?$", "");//去掉后面无用的零

  s = s.replaceAll("[.]$", "");//如小数点后面全是零则去掉小数点

}

 

2. 使用NumberFormat

import java.text.NumberFormat
 
NumberFormat nf = NumberFormat.getInstance();

String value = nf.format(321.32100);

输出为321.321

 

相关文章:

  • 2021-07-10
  • 2021-12-12
  • 2021-07-29
  • 2021-12-08
  • 2022-12-23
  • 2021-10-13
  • 2021-10-31
  • 2022-12-23
猜你喜欢
  • 2021-10-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案