자바스크립트/기초
Math.trunc()
김마리모
2023. 6. 28. 21:10
프로그래머스 코딩 기초 트레이닝 문제를 풀다가 본 Math.trunc()
Math.trunc() 함수는 주어진 값의 소수부분을 제거하고 숫자의 정수부분을 반환합니다.
console.log(Math.trunc(13.37));
// Expected output: 13
console.log(Math.trunc(42.84));
// Expected output: 42
console.log(Math.trunc(0.123));
// Expected output: 0
console.log(Math.trunc(-0.123));
// Expected output: -0
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc
Math.trunc() - JavaScript | MDN
The Math.trunc() static method returns the integer part of a number by removing any fractional digits.
developer.mozilla.org
반응형