[JavaScript] Math.trunc()와 Math.floor()의 차이
Math.trunc()와 Math.floor()는 둘 다 소수를 다룰 때 사용되는 메서드이다. 그러나 이 두 메서드는 동작의 차이가 있다. Math.trunc() Math.trunc() 메서드는 주어진 숫자의 소수점 이하를 제거하고 정수 부분만 반환한다. console.log(Math.trunc(5.05)); // Expected output: 5 console.log(Math.trunc(-5.99)); // Expected output: -5 양수, 음수 상관없이 정수를 반환한다. 예를 들어, Math.trunc(5.05)는 5를 반환하고, Math.trunc(-5.99)는 -5를 반환한다. Math.floor() Math.floor() 메서드는 주어진 숫자의 소수를 버리고 그 숫자보다 작거나 같은 가..
언어/JavaScript
2024. 1. 8. 11:03
- Total
- Today
- Yesterday