상세 컨텐츠

본문 제목

[JavaScript] 숫자 소수점 없애기 반올림, 올림, 내림round(), ceil(), floor()

Coding/JS

by hwlink 2021. 10. 24. 20:32

본문

round() 반올림 해준다.

round(2.4) : 2

round(5.6) : 6

round(7.5) :8

round(-2.3) : -2

round(-4.6) : -5

round(-5.4) : -5

 

ceil() 천장까지 간다. 올림해준다.

ceil(98.1) = 100

ceil(0.1) = 1

ceil(7.9) = 8

ceil(7.4) = 8

ceil(-5.55) = -5

floor() 바닥까지 간다. 내림해준다.

소수점 아래를 무조건 무시한다.

floor(7.6) = 7

floor(2.9) = 2

floor(-1.2) = -2 

 

 

관련글 더보기