영상
개념
<script>
/*
[개념] 소수점 처리
[1] 올림
- Math.ceil(x) : 주어진 값에 소수점 올림하여 정수를 반환
[2] 버림
- Math.floor(x): 주어진 값에 소수점 내림하여 정수를 반환
[3] 반올림
- Math.round(x): 주어진 값에 소수점 반올림하여 정수를 반환
- 0, 1, 2, 3, 4이면 버리고, 5, 6, 7, 8, 9이면 올림
*/
console.log(10 / 4);
console.log(Math.ceil(10 / 4));
console.log(Math.floor(10 / 4));
console.log(Math.round(2.5));
console.log(Math.round(2.4));
document.write((10 / 4) + "<br>"); // 2.5
document.write(Math.ceil(10 / 4) + "<br>"); // 3
document.write(Math.floor(10 / 4) + "<br>"); // 2
document.write(Math.round(2.5) + "<br>"); // 3
document.write(Math.round(2.4) + "<br>"); // 2
</script>
Java
복사