-4

I have two var in html i want that when i divide first var with second then it show data like 19.30 instead of 19.3

var a =20;
var b=386;
var c=b/a

so c should show 19.30 instead of 19.3 in html java script.

Ali Sajad
  • 59
  • 1
  • 3
  • 10
  • why downvote if any body does not gets problem solved then he can post to get the information about the problem – Ali Sajad Apr 16 '13 at 06:44
  • Dup: http://stackoverflow.com/questions/2433122/how-to-add-a-trailing-zero-to-a-price-with-jquery/2433183#2433183 – elclanrs Apr 16 '13 at 06:46
  • Dup: http://stackoverflow.com/questions/8225558/how-do-i-round-to-2-decimal-places/8225574#8225574 – elclanrs Apr 16 '13 at 06:46
  • @AliSajad you get downvoted because it seems like there was no effort to solve it by yourself nor to use the search. – pdu Apr 16 '13 at 07:00

2 Answers2

0
var c_formatted = c.toFixed(2);
console.log(c_formatted); // 19.30
Barmar
  • 741,623
  • 53
  • 500
  • 612
0

As @Barmar suggested, i would also suggest the same. but make sure that the toFixed() will return a string not a number, so that we have to cast it manually either by inserting + operator in the beginning or by using Number() function.

var a =20;
var b=386;
var c= +(b/a).toFixed(2);
Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130