java除法保留指定位数的小数

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

结果如下

猜你喜欢

转载自www.cnblogs.com/837634902why/p/10972840.html