Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting integer to float with precision 2 using Javascript or Jquery

I want to convert the integer to floating number with precision 2. ie. -

11 => 11.00

45 => 45.00

Please help me.

Thank you.

like image 369
teenu Avatar asked Jul 27 '12 09:07

teenu


People also ask

What is float precision JavaScript?

The representation of floating points in JavaScript follows the IEEE-754 format. It is a double precision format where 64 bits are allocated for every floating point.

Which is the method to convert user input into a float value in JavaScript?

By using parseFloat() Method.


1 Answers

Use .toFixed:

var num = 45;
num.toFixed(2); //"45.00"
like image 93
Esailija Avatar answered Oct 04 '22 19:10

Esailija