Working with numbers in JavaScript

Make a string into a number for use in calculations : Number(string);

Round a number to certain place after making calulations:
The Math.round() function returns the value of a number rounded to the nearest integer.

Math.round(x)

The Math.abs() function returns the absolute value of a number.

var abs = Math.abs(x);

The Math.floor() function returns the largest integer less than or equal to a number. This is basically to round DOWN:

Math.floor(x) 

The Math.ceil() function returns the smallest integer greater than or equal to a number. This is to round UP:

Math.ceil(x)

Leave a Reply