Difference between ceil(),floor() and abs() in javascript

Difference between ceil(),floor() and abs() in javascript

Math object provide properties and functions for mathematical function and constants. it is not a constructor. Math is a static it can be called without creating it.

ceil() :

The ceil() is a math function. it rounds the value "UPWARDS" to the nearest integer

Example :
Math.ceil(.95); //Output 1
Math.ceil(4); //Output 4
Math.ceil(7.004); //Output 8
Math.ceil(-0.009); //Output -0
Math.ceil(-4); //Output -4

floor() : 

The floor() is a math function. it rounds the value "DOWNWARDS" to the nearest integer

Example :
Math.floor(4.7); //Output 4
Math.floor(.95); //Output 0
Math.floor(7.004); //Output 7
Math.floor(-4); //Output -4
Math.floor(-4.7); // Output -5

abs() :

The abs() is a math function. it provide absolute positive value to the number

Example :
Math.abs(-4.4); //Output 4.4
Math.abs(0.95); //Output 0.95
Math.abs(5.2); //Output 5.2

0 Comments

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed

>