하나씩 하나씩 실습을 통해서 알아보겠습니다.
Math.round();
Math.floor();
Math.ceil();
Math.trunc();
Math.round(); 의미는 반올림 으로 반환합니다.
0.5 이상이면 올림0.5 미만이면 내림 Math.round(6.2); // 결과 6
Math.round(6.5); // 결과 7
Math.round(-7.49); // 결과 -7
Math.round(-7.5); // 결과 -7
Math.round(-7.51); // 결과 -8
Math.floor(); 의미는 음수 일 때 올림하여 반환합니다.
Math.floor(6.2); // 결과 6
Math.floor(-6.2); // 결과 -7
Math.floor(-8.6); // 결과 -9
Math.ceil(); 의미는 양수 일 때 올림하여 반환합니다.
Math.ceil(6.2); // 결과 7
Math.ceil(-6.2); // 결과 -6
Math.trunc(); 의미는 양수 일 때 올림하여 반환합니다.
Math.trunc(6.2); // 결과 6
Math.trunc(-6.2); // 결과 -6