I have the following code and have tried everything to parse all the numbers so that IE doesn't throw a fit:
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_le开发者_开发百科ft = 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));
});
Does anyone have an answer for me as to why
first_payment = Math.ceil(subscription+interim_val).toFixed(2);
does not get calculated on IE8?
Please, I'm desperate over here.
Thanks in advance.
You shouldn't use Number
to cast as numeric, you should instead use parseInt
or parseFloat
and then check the result with isNaN
. In addition, you are not verifying the output of daysLeftMonth
or daysInMonth
, and the days_left
value may contain a NaN
value which would pollute the subscription+interim_val
operation taking place inside the Math.ceil.
精彩评论