반응형
소수점 고려
1) ceil
- 반환: 올림한 값
- 천장!
2) floor
- 반환: 내림한 값
- 바닥!
3) round
- 반환: 반올림한 값
- 그 중간!
공통점
- null 넣으면 0 반환함
- 숫자 아닌 값 넣으면 Nan 반환함
소수점 고려X
trunc
- 반환: 소수점 버리고 숫자의 정수부분만
- 위의 셋과 달리 소수점과 상관없이 단순하게 동작함
https://stackabuse.com/rounding-numbers-in-javascript-using-ceil-floor-and-round/
Rounding Numbers in JavaScript using ceil(), floor() and round()
In this guide, we'll take a look at how to round a number to an integer (whole number) in JavaScript, using ceil(), floor() and round(), with practical examples.
stackabuse.com
반응형
'Front-End: Web > JavaScript' 카테고리의 다른 글
[js] NaN(Not A Number)이란? (+isNaN, Number.isNaN) (0) | 2022.09.10 |
---|---|
[js] parseInt vs plus(+) (0) | 2022.09.10 |
[js] 문자열.repeat() 안에 정수가 아닌 수를 넣으면? (0) | 2022.09.10 |
[js] 문자열 자르기 (slice, splice, split, substring, substr) (0) | 2022.09.10 |
[apple-js] Part 1: (0) | 2022.03.23 |