Categories
Web development

JavaScript Math.trunc()

JavaScript Math.trunc()

The JavaScript Math.trunc() returns the integer part of a number.

Syntax:

Math.trunc(number)

Note: The JavaScript Math.trunc() won’t round the number up/down to the nearest integer, but simply remove the decimals.

Example:

<!DOCTYPE html>
<html>
<body>

<p id="example"></p>

<script>
document.getElementById("example").innerHTML = Math.trunc(7.57);
</script>

</body>
</html>

Output:

The JavaScript Math.trunc() returns the integer part of a number:


Note: The JavaScript Math.trunc() is not supported in Internet Explorer.

Enjoy coding!

Read also:

JavaScript Math Object

JavaScript Math Object Properties

JavaScript Math.round()