tags:

views:

54

answers:

3

Hi,

I have a number in javascript, e.g. 556633.

How can I convert this to be £5566.33

Thanks Jon

+2  A: 

Try

"£"+556633/100
S.Mark
I'd say `"£" + (556633 / 100)` to be sure.
Skilldrick
Works for this *exact* case, but how about if the number 556633.9 was fed in. Then it gives too many decimal places.
Rob Levine
You are right Rob Levine, if OP want 2 decimal places, need to do .toFixed(2), but there is answers for that already, I wouldn't update my answer.
S.Mark
+6  A: 

Try this:

var num = 10;
var result = num.toFixed(2); // result will equal 10.00
knipknap
+1 for ensuring 2 decimal places (plus toFixed also handles rounding)
Rob Levine
A: 

This works:

var currencyString = "£" + (amount/100).toFixed(2);
Rob Levine