views:

3354

answers:

3

I'm using the Jquery calculation and have just about everything working properly, but I need the total to display as 99.90, not 99.9 <-- Just an example. Here is a link the form I'm using. [link text][1]

[1]: So... .toFixed(), isn't working for some reason, when it should be! I can't find a mask that would work with this problem. Anyone.. any other ideas??

+2  A: 

You can use toFixed

var num = 99.9;
num.toFixed(2);
Daniel Moura
I've also tried this, and nothing worked.
Michael Stone
A: 

Instead of this line:

$(".sumit").sum("keyup", "#totalSum");

Use:

$('.sumit').keyup(function(){
  var totalsum = $('.sumit').sum();
  $('#totalSum').val(Number(totalsum).toFixed(2));
});

Hope that helps

Al
Tried it. Still getting the same result. I'm wondering if the calculation has an overwrite within it?
Michael Stone
The calculation is done before formatting the number so it shouldn't be that. Still staring at the code and scratching my head ;)
Al
Aha, I think the variable totalsum is a string not a number, so .toFixed doesn't exist. Updating original answer with new code
Al
Perfect! Was right over my head! Input values are strings, you have to convert to a number. Thanks Al!
Michael Stone