How can I move the decimal point to the 100ths of an integer?

qodeninja picture qodeninja · Dec 10, 2010 · Viewed 9.4k times · Source

This seems like a silly question but I cant figure out how to convert an integer number that represent cents to dollars.

3000 -> 30.00

in javascript...

I was using ParseFloat but it's only giving me back the integer =/ I need to always display the cents even if its 0.

Answer

user113716 picture user113716 · Dec 10, 2010

Use toFixed().

var num = 3000;

alert( (num/100).toFixed( 2 ) ); // alerts 30.00