Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
177
rated 0 times [  181] [ 4]  / answers: 1 / hits: 84438  / 14 Years ago, fri, december 10, 2010, 12:00:00

Possible Duplicate:

JavaScript: formatting number with exactly two decimals






Getting a bit muddled up using variables and now cant seem to get calculation to work at all!?



 $(#discount).change(function(){
var list = $(#list).val();
var discount = $(#discount).val();
var price = $(#price);
var temp = discount * list;
var temp1 = list - temp;
var total = parseFloat($(this).temp1()).toFixed(2);

price.val(total);
});

More From » jquery

 Answers
32

$(this).temp1() looks particularly out of place, I think you just meant to use the temp1 variable. Since it's already a number, you don't need to use parseFloat on it either:



$(#discount).change(function() {
var list = $(#list).val();
var discount = $(#discount).val();
var price = $(#price);
var temp = discount * list;
var temp1 = list - temp;
var total = temp1.toFixed(2);

price.val(total);
});

[#94651] Wednesday, December 8, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
herman

Total Points: 110
Total Questions: 90
Total Answers: 108

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
3 Years ago
;