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); }
本文来自博客园,作者:每天都要学一点,欢迎讨论和转载,转载请注明原文链接:https://www.cnblogs.com/yanan7890/p/15067015.html