%
반올림 Math.round(), 나머지 연산자
반올림 Math.round(), 나머지 연산자
2022.03.16반올림 - Math.round() 실수를 소수점 첫 째자리에서 반올림한 정수를 반환 long result = Math.round(4.52);// result에 5가 저장된다. 이런 방식으로 사용한다. 이번에는 예제를 보자. [Ex3_11] public class Ex3_11 { public static void main(String argsp[]){ double pi = 3.141592; double shortPi = Math.round(pi*1000) / 1000.0; System.out.println(shortPi); } } 만약에 소수점 넷째자리에서 반올림을해서 3.142를 얻고싶으면 어떻게 해야하는지를 보여준 예제이다. 이 Math.round()라는 메서드는 첫째자리에서만 반올림 하기 때문에, 우..