- 결론 -
양수일 때는 동일한 결과.
음수일 때, 값의 소수점만 버리고 싶다면 parseInt(string, radix)
소수점 아래에서 -1 내림한 값을 원한다면 Math.floor(number)
parseInt('12') // 12
Math.floor('12') // 12
parseInt('12 34 56') // 12
Math.floor('12 34 56') // NaN
ref.
parseInt() - JavaScript | MDN
The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems).
developer.mozilla.org
Math.floor() - JavaScript | MDN
The Math.floor() static method always rounds down and returns the largest integer less than or equal to a given number.
developer.mozilla.org
'A-HA💡 > JS' 카테고리의 다른 글
[JS] 배열에서 특정 값 찾는 방법 ⭐️ (0) | 2023.12.22 |
---|---|
[JS/알고리즘] 백준 2903. 중앙 이동 알고리즘 (안 풀릴 땐 멈춰보자) (0) | 2023.11.29 |
[JS] 깊은 복사(deep copy)와 얕은 복사(shallow copy) (0) | 2023.11.27 |
[JS] 내장함수 map filter reduce foreach (0) | 2023.11.27 |
[JS] 비구조화 할당🖍️ (0) | 2023.11.07 |