尝试将数字格式化为2位小数jQuery [英] Trying to format number to 2 decimal places jQuery
本文介绍了尝试将数字格式化为2位小数jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
JavaScript:格式化数字正好两位小数
使用变量有点混乱,现在似乎无法让计算完全正常工作!?
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);
});
推荐答案
$(this)。 temp1()
看起来特别不合适,我想你只是想使用 temp1
变量。由于它已经是一个数字,你不需要在它上面使用 parseFloat
:
$(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);
});
这篇关于尝试将数字格式化为2位小数jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文