Java & Spring
[JAVA] round() 사용법
doitdoik
2022. 3. 15. 18:43
728x90
Math.round()
round()함수는 실수의 소수점 첫번째 자리를 반올림하여 정수로 리턴시킨다.
public static long round(double d)
public static int round(float f)
Math.round() 예제
double pie = 3.14159265358979;
System.out.println(Math.round(pie)); // 3
System.out.println(Math.round(pie*100)/100.0); // 3.14
System.out.println(Math.round(pie*1000)/1000.0); // 3.142
728x90