▶Math.ceil() : 올림 (실수형 유지)
▶Math.floor() : 내림 (실수형 유지)
▶Math.rint() : 반올림 (실수형 유지)
▶Math.round() : 반올림 (int형으로 반환)
System.out.println(Math.ceil(3.14));
System.out.println(Math.floor(3.14));
System.out.println(Math.rint(3.14));
System.out.println(Math.rint(3.51));
System.out.println(Math.round(3.51));
4.0
3.0
3.0
4.0
4
반응형
'JAVA > API' 카테고리의 다른 글
[자바] StringBuilder 사용하는 이유, 사용법, 함수(메소드) 정리 (4) | 2021.04.04 |
---|---|
[자바] String 클래스와 메소드 (0) | 2021.03.29 |
[자바] 실수의 오차를 없애주는 BigDecimal (0) | 2021.03.27 |
[자바] 숫자를 문자로 바꾸는 메소드 toString() (0) | 2021.03.27 |
[자바] Math.max(), Math.min() (0) | 2021.03.27 |