Android 保留小数点后两位,并采取四舍五入

 //小数点后两位四舍五入
    private double formatDouble2(double d) {
        BigDecimal bigDecimal = new BigDecimal(d);
        double bg = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        return bg;
    }

猜你喜欢

转载自www.cnblogs.com/niupi/p/11428915.html