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