-3

I am trying to round a number to 2 decimal places . i am showing with an example

var k =10.3;
alert(parseFloat(k),2); // outputs 10.3
alert(Math.round(k).toFixed(2)); // outputs 10.00

the result i need is 10.30 what is the solution for this .

please help

thanks

  • 1
    https://www.google.com/search?hl=en&q=How+can+i+round+a+number+to+2+decimal+places(compelsory)+in+javascript This already shows you quite a lot of good answers to your question. – Joeytje50 May 25 '14 at 15:52
  • see this http://stackoverflow.com/questions/6134039/format-number-to-always-show-2-decimal-places – Ibrahim Khan May 25 '14 at 15:53

2 Answers2

4
var k = 10.3;
k.toFixed(2);  // 10.30
VtoCorleone
  • 16,813
  • 5
  • 37
  • 51
2

To format a number using fixed-point notation, you can simply use the toFixed method:

(10.8).toFixed(2); // 10.80

var num = 2.4;
alert(num.toFixed(2)); // 2.40
Joeytje50
  • 18,636
  • 15
  • 63
  • 95
lili-crash
  • 53
  • 6