我正在尝试将两个十进制值相加,但返回的总和是纯整数。怎么了?我找不到它。欢迎任何帮助。
jQuery(".delivery-method #ship_select").change(function(){
var cost = jQuery(this).val();
jQuery("#delivery_cost").val(cost); //returns 20.00
var tot = parseInt(cost) + parseInt(total); //total returns 71.96
});
使用代码我只得到 91
而不是 91.96
最佳答案
使用 parseFloat()
而不是 parseInt()
。
jQuery(".delivery-method #ship_select").change(function(){
var cost = jQuery(this).val();
jQuery("#delivery_cost").val(cost); //returns 20.00
var tot = parseFloat(cost) + parseFloat(total); //total returns 71.96
});
关于javascript - 不能使用 jQuery 添加两个小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9987734/