Math.trunc() - 소수부분 버리기

hello__0·2022년 8월 3일
0

Math.trunc() 함수는 주어진 값의 소수부분을 제거하고 숫자의 정수부분을 반환합니다.
함수는 주어진 값이 양수이건 음수이건 상관없이 소수점 이하 우측부분을 제거하는 매우 단순한 동작을 합니다.

trunc() 함수는 Math의 정적 메서드이기 때문에 사용자가 생성한 Math 객체의 메서드로 호출하는 것이 아닌 항상 Math.trunc() 형태로 호출해야 합니다. (Math 는 생성자가 아닙니다).

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
profile
자라나라 나무나무

0개의 댓글