开发者

IE8 not able to calculate Math.ceil() [closed]

开发者 https://www.devze.com 2023-02-19 12:37 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消