java 4舍5入
作者:互联网
/** * @Dscription: scale,保留几位小数点 molecular 分子,denominator 分母 * @Author: zyn * @Date: 2021/7/27 */ private static BigDecimal round(double molecular,double denominator,int scale){ double total = (molecular * 100.0) / denominator; double total2 = new BigDecimal(total).setScale(scale, BigDecimal.ROUND_HALF_UP).doubleValue(); return new BigDecimal(total2); } /** * @Dscription: scale,保留几位小数点 v,需要操作的数 * @Author: zyn * @Date: 2021/7/27 */ private static BigDecimal round(double f,int scale){ return new BigDecimal(f).setScale(scale, RoundingMode.UP); }
标签:scale,java,BigDecimal,double,denominator,new,molecular 来源: https://www.cnblogs.com/yanan7890/p/15067015.html