Math.floor() function in javascript

What is Math?

Before we learn about Math.random() function I would like to tell you that Math is an object in javascript.
The Math object includes several mathematical constants and methods.
Math object allows you to perform mathematical tasks.
Math is not a constructor, hence all properties and methods can be called by using Math as an object without creating it.


var a = Math.PI; //3.141592653589793
var b = Math.sqrt(25); //5


The floor() method rounds a number to the nearest integer downwards side, and returns the result.
Input can be positive number or negative number;

var a = Math.floor(0.50); //a = 0
var b = Math.floor(0.90); //b = 0
var c = Math.floor(8); //c = 8
var d = Math.floor(9.1); //d = 9
var e = Math.floor(-3.1); //e = -4
var f = Math.floor(-8.9); //f = -9
var g = Math.floor(0); //g = 0

Click on below topics for step by step tutorial.
How to get random element from Javascript Array and Display it.
Define an array in javascript
Math.random() function in javascript
array.length in javascript

Comments are closed.