float price=(float) 625.2135; DecimalFormat decimalFormat=new DecimalFormat(".00");//这里有几个0就保留几位,如果小数不足位,会以0补足. String price1=decimalFormat.format(price);//format 返回的是字符串 System.out.println(price1);
结果如下

本文介绍如何使用Java中的DecimalFormat类对浮点数进行格式化处理,具体演示了保留小数位数的方法,并提供了代码实例。
float price=(float) 625.2135; DecimalFormat decimalFormat=new DecimalFormat(".00");//这里有几个0就保留几位,如果小数不足位,会以0补足. String price1=decimalFormat.format(price);//format 返回的是字符串 System.out.println(price1);
结果如下

转载于:https://www.cnblogs.com/837634902why/p/10972840.html
401
1977
5360
3167
1332

被折叠的 条评论
为什么被折叠?