Skip to content Skip to sidebar Skip to footer

Javascript Always Returns Float Numbers

Thats my jquery code. And the variable 'procenti' always return like 92.3076923076923 % long decimal number. I would like that number to be without the decimals, only 92%. I tried

Solution 1:

round() function will round off value.

Math.round(procenti);

Otherwise there are another functions ceil() & floor()

Solution 2:

You should use either

Math.floor() 

It returns the largest integer less than or equal to a given number.

or

Math.ceil() 

It returns the smallest integer greater than or equal to a given number.

or

Math.round()

It returns the value of a number rounded to the nearest integer.

It depends on what you actually want.

Solution 3:

You could do something like this:

functionstrip(number) {
return (parseFloat(number).toPrecision(12));

}

Hope this helps && pozdrav iz Velenja! :)

Post a Comment for "Javascript Always Returns Float Numbers"