JavaScript truncate number | trunc( ) Method example

Use trunc() method in JavaScript to get truncate number. Where this method returns the integer part of a number. It’ simply remove the decimals.

Note: This method will NOT round the number up/down to the nearest integer.

Syntax

Example of JavaScript truncate number | trunc( ) Method

Let’s cuts off the dot and the digits to the right of it in JS.

Output:

JavaScript truncate number trunc Method

Q: How to truncate float in JavaScript?

Answer: Use toFixed() function.

Do comment if you have any doubts and suggestion on this tutorial.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.