我有以下代码,并已尝试一切方法来解析所有数字,以便 IE 不会出错:
var firt_payment = 0.0;
var subscription = 0.0;
var no_policies = 0;
var policy_cost = 100.0;
if (typeof interval == "undefined") {
var interval = 0;
}
var days_left = daysLeftMonth(interval);
var days_month = daysInMonth();
$("input[name^='policies']:checkbox").change(function() {
var el = $(this);
if (el.is(":checked")) {
no_policies++;
}
if (el.is(":not(:checked)")) {
no_policies--;
}
subscription = Number(no_policies*policy_cost);
var interim_val = 0.0;
if (no_policies > 0) {
interim_val = no_policies*(policy_cost/days_month)*days_left;
}
first_payment = Math.ceil(subscription+interim_val).toFixed(2);
$("td#first_payment").text("R "+first_payment);
$("input#first_payment_txt").val(first_payment);
$("td#subscription").text("R "+subscription.toFixed(2));
});
有谁能告诉我为什么吗
first_payment = Math.ceil(subscription+interim_val).toFixed(2);
在 IE8 上不计算?
拜托,我在这里很绝望。
提前致谢。
最佳答案
您不应使用 Number
转换为数字,而应使用 parseInt
或 parseFloat
,然后使用 检查结果>为NaN
。此外,您没有验证 daysLeftMonth
或 daysInMonth
的输出,并且 days_left
值可能包含 NaN
值会污染 Math.ceil 内发生的 subscription+interim_val
操作。
关于javascript - IE8无法计算Math.ceil(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5410623/