Languages
[Edit]
EN

JavaScript - Math.trunc() method example

11 points
Created by:
Maison-Humphries
791

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


1. Documentation

Edit
SyntaxMath.trunc(number)
Parametersnumber - integer or float number value (primitive value).
Result

Integer part of number value  (primitive value).

If number is NaN it returns NaN.

If number is -Infinity it returns -Infinity.

If number is +Infinity it returns +Infinity.

Description

Math.trunc() is a static method that takes one parameter and returns integer part of number passed as argument. Integer numbers are returned without any changes.

Note: this method has been introduced in ES 2015.

2. Polyfill example

Edit

This example shows polyfill solution for lack of the method.

References

Edit
  1. Truncation - Wikipedia

Alternative titles

  1. JavaScript - Math.trunc() documentation with examples
  2. js - Math.trunc() method documentation with examples
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - Math documentation (EN)

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join