Front-End

[javascript]Math()함수를 이용한 올림, 버림, 반올림

Math()함수 사용방법

[Math.floor() : 소수점 버림 ]

document.write(Math.floor(123.456)); →124
document.write(Math.floor(123.567)); →124

[Math.round() : 소수점 반올림 ]

document.write(Math.round(123.456)); →123
document.write(Math.round(123.567)); →124

[Math.ceil() : 소수점 올림 ]

document.write(Math.ceil(123.456)); →124 
document.write(Math.ceil(123.567)); →124 

[toFixed() : 소수점 이하 숫자를 지정한 자릿수만 남기고  반올림]

document.write((123.456).toFixed(0)); →123
document.write((123.456).toFixed(2)); →123.46
document.write((123.456).toFixed(4)); →123.4560

Hi, I’m 관리자