Math.trunc() method, which removes any decimal digits from a number without rounding it.
To truncate a number to a specific number of decimal places, you can multiply it by a power of 10, apply
Math.trunc(), and then divide by the same power of 10. For example, to truncate a number to 2 decimal places, you can use the following code:
const num = 3.14159; const truncatedNum = Math.trunc(num * 100) / 100; console.log(truncatedNum); // 3.14
This code multiplies the original number by 100 to move the decimal point two places to the right, applies
Math.trunc() to remove any decimal digits, and then divides by 100 to move the decimal point back to its original position.