JavaScript: Rounding to two decimal places. Not less than two

Posted by Abs on Stack Overflow See other posts from Stack Overflow or by Abs
Published on 2009-11-13T01:46:18Z Indexed on 2010/04/21 5:23 UTC
Read the original article Hit count: 248

Hello all,

I have this line of code which rounds my numbers to 2 decimal places. But the thing is I get numbers like this. 10.8, 2.4 etc. These are not my idea of 2 decimal places so how I can improve this:

Math.round(price*Math.pow(10,2))/Math.pow(10,2);

I want numbers like 10.80, 2.40 etc. Use of JQuery is fine with me.

Thanks for any help.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery