原创

java-获取带有百分比的四舍五入的BigDecimal除法,要先乘以100

public static void main(String[] args) {
BigDecimal pass = new BigDecimal("1");
BigDecimal total = new BigDecimal("36");
BigDecimal divide = pass.multiply(Constants.BIG_DECIMAL_100).divide(total, 2, RoundingMode.HALF_UP);
BigDecimal multiply = divide.multiply(new BigDecimal(100));
System.out.println(multiply); //0.3

BigDecimal pass2 = new BigDecimal("1");
BigDecimal total2 = new BigDecimal("36");
BigDecimal multiply2 = pass2.multiply(new BigDecimal(100)).divide(total2, 2, RoundingMode.HALF_UP);
System.out.println(multiply2);//0.78 正确
获取带有百分比的四舍五入的BigDecimal除法,要先乘以100

}

正文到此结束
本文目录