You can use the trunc() method to get the integer part of a number by removing any fractional digits. This method was added in ECMAScript 6 and supported by the latest browsers such as Chrome, Firefox, Safari, Opera, and Edge browsers. Not supported in Internet Explorer.
Alternatively, you can also try other methods like floor(), ceil() and round() to round a number. Let's take a look at the following example to understand how it works:
Use the JavaScript
trunc()MethodYou can use the
trunc()method to get the integer part of a number by removing any fractional digits. This method was added in ECMAScript 6 and supported by the latest browsers such as Chrome, Firefox, Safari, Opera, and Edge browsers. Not supported in Internet Explorer.Alternatively, you can also try other methods like
need an explanation for this answer? contact us directly to get an explanation for this answerfloor(),ceil()andround()to round a number. Let's take a look at the following example to understand how it works: