convert a float number to a number in JavaScript

Math.floor()

The Math.floor() function always rounds down and returns the largest integer less than or equal to a given number.

 

float  = 5.677;

var intvalue = Math.floor( float );
console.log(intvalue) //5

 

Math.ceil()

The Math.ceil() function always rounds up and returns the smaller integer greater than or equal to a given number.

float  = 5.677;

var intvalue = Math.ceil( float ); 
console.log(intvalue) //6

 

Math.round()

The Math.round() function returns the value of a number rounded to the nearest integer.

 



float  = 5.677;
var intvalue = Math.round( float );
console.log(intvalue)

Tags:

Share:

Related posts