BigDecimal a1 = new BigDecimal("10");
BigDecimal a2 = new BigDecimal("3");
BigDecimal b1 = new BigDecimal("10");
BigDecimal b2 = new BigDecimal("6");
System.out.println(a1.divide(a2, 2, RoundingMode.HALF_UP));
System.out.println(b1.divide(b2, 2, RoundingMode.HALF_UP));
본래 값
3.33
1.67
초기값 | 결과 |
---|---|
5.5 | 5 |
2.5 | 2 |
1.6 | 2 |
1.1 | 1 |
1.0 | 1 |
-1.0 | -1 |
-1.1 | -1 |
-1.6 | -2 |
-2.5 | -2 |
-5.5 | -5 |
BigDecimal a1 = new BigDecimal("10");
BigDecimal a2 = new BigDecimal("3");
BigDecimal b1 = new BigDecimal("10");
BigDecimal b2 = new BigDecimal("6");
System.out.println(a1.divide(a2, 2, RoundingMode.UP));
System.out.println(b1.divide(b2, 2, RoundingMode.UP));
본래 값
3.34
1.67
초기값 | 결과 |
---|---|
5.5 | 5 |
2.5 | 2 |
1.6 | 1 |
1.1 | 1 |
1.0 | 1 |
-1.0 | -1 |
-1.1 | -1 |
-1.6 | -1 |
-2.5 | -2 |
-5.5 | -5 |
BigDecimal a1 = new BigDecimal("10");
BigDecimal a2 = new BigDecimal("3");
BigDecimal b1 = new BigDecimal("10");
BigDecimal b2 = new BigDecimal("6");
System.out.println(a1.divide(a2, 2, RoundingMode.DOWN));
System.out.println(b1.divide(b2, 2, RoundingMode.DOWN));
본래 값
3.33
1.66
초기값 | 결과 |
---|---|
5.5 | 6 |
2.5 | 3 |
1.6 | 2 |
1.1 | 2 |
1.0 | 1 |
-1.0 | -1 |
-1.1 | -1 |
-1.6 | -1 |
-2.5 | -2 |
-5.5 | -5 |
BigDecimal a1 = new BigDecimal("-10");
BigDecimal a2 = new BigDecimal("3");
BigDecimal b1 = new BigDecimal("-10");
BigDecimal b2 = new BigDecimal("6");
System.out.println(a1.divide(a2, 2, RoundingMode.HALF_DOWN));
System.out.println(b1.divide(b2, 2, RoundingMode.HALF_DOWN));
본래값
-3.33
-1.67
초기값 | 결과 |
---|---|
5.5 | 6 |
2.5 | 2 |
1.6 | 2 |
1.1 | 1 |
1.0 | 1 |
-1.0 | -1 |
-1.1 | -1 |
-1.6 | -2 |
-2.5 | -2 |
-5.5 | -6 |