14th January 2008 - 6 minutes read time
All of the maths functions in JavaScript are kept in a handy object called Math, which contains a number of different functions.
To get the absolute value of a number use the abs() function.
Math.abs(3.14159265) // returns 3.14159265
Rounding a number is done by either the round() function to round to the nearest integer, the ceil() function to round up to the nearest integer and the floor() function to round down to the nearest integer.
Math.ceil(3.14159265) // returns 4
Math.floor(3.14159265) // returns 3
Math.round(3.14159265) // returns 3
To find the exponent of a number use the exp() function.
Math.exp(3.14159265) // returns 23.140692549708973
The log() method returns the natural logarithm (base E) of a number.