不能使用jQuery添加两个十进制数字 [英] can't add two decimal numbers using jQuery
本文介绍了不能使用jQuery添加两个十进制数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试添加两个十进制值,但返回的总和是纯整数。怎么了?我找不到它。欢迎任何帮助。
I am trying to add two decimal values but the returned sum is pure integer. What is wrong? I can't find it. any help will be welcome.
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
});
这篇关于不能使用jQuery添加两个十进制数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文