FANDOM


The Math object is an object that allows you to perform mathematical tasks on numbers. This object includes several mathematical methods. JavaScript Examples

absEdit

Data type function
Return type number
Parameter list x (number)
Standard ECMA-262 §15.8.2.1
Documentation Mozilla, Microsoft

Returns the absolute value of (that is, a positive number of the same magnitude as) x.

Math.abs(-1) // 1
Math.abs(2)  // 2
Math.abs(3)  // 3
Math.abs(-4) // 4

roundEdit

Data type function
Return type number
Parameter list x (number)
Standard ECMA-262 §15.8.2.15
Documentation Mozilla, Microsoft

Rounds the number to the nearest integer.

Math.round(12.3)    // 12
Math.round(12.4999) // 12
Math.round(12.5)    // 13
Math.round(12.6)    // 13

If you want to round a number to a certain precision, such as for display as currency, you may wish to see Number.toFixed instead.

PIEdit

Data type function
Return type number
Parameter list none
Standard
Documentation Mozilla

Returns the number of pi (π).

Math.PI // 3.1415926

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.