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

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

结果如下

 

posted @ 2019-06-04 12:33  王怀宇  阅读(3876)  评论(0编辑  收藏  举报