javascript - Is Math.ceil() & Math.round() supported on IE8? - Stack Overflow

I have a Javascript function that calculates a value and re-inserts the value into a <td> while a

I have a Javascript function that calculates a value and re-inserts the value into a <td> while also injecting the value into a hidden <input>.

This is my function:

$("input[name^='policies']:checkbox").change(function() {
    var el = $(this);

    if (el.is(":checked")) {
        no_policies++;
    }

    if (el.is(":not(:checked)")) {
        no_policies--;
    }

    subscription = no_policies*policy_cost;
    first_payment = Math.ceil(subscription+no_policies*(policy_cost/days_month)*days_left).toFixed(2);

    alert(first_payment);

    $("td#first_payment").text("R "+first_payment);
    $("input#first_payment_txt").val(first_payment);
    $("td#subscription").text("R "+subscription.toFixed(2));    
});

Everything works on IE8 up until this statement:

first_payment = Math.ceil(subscription+no_policies*(policy_cost/days_month)*days_left).toFixed(2);

I suspect IE8 is having trouble with Math.ceil, is that true? Also, is there any other function/method I can use to circumvent this?

Thanks in advance.

I have a Javascript function that calculates a value and re-inserts the value into a <td> while also injecting the value into a hidden <input>.

This is my function:

$("input[name^='policies']:checkbox").change(function() {
    var el = $(this);

    if (el.is(":checked")) {
        no_policies++;
    }

    if (el.is(":not(:checked)")) {
        no_policies--;
    }

    subscription = no_policies*policy_cost;
    first_payment = Math.ceil(subscription+no_policies*(policy_cost/days_month)*days_left).toFixed(2);

    alert(first_payment);

    $("td#first_payment").text("R "+first_payment);
    $("input#first_payment_txt").val(first_payment);
    $("td#subscription").text("R "+subscription.toFixed(2));    
});

Everything works on IE8 up until this statement:

first_payment = Math.ceil(subscription+no_policies*(policy_cost/days_month)*days_left).toFixed(2);

I suspect IE8 is having trouble with Math.ceil, is that true? Also, is there any other function/method I can use to circumvent this?

Thanks in advance.

Share Improve this question asked Mar 23, 2011 at 18:27 Anriëtte MyburghAnriëtte Myburgh 13.5k11 gold badges52 silver badges72 bronze badges 4
  • Are you sure the values are all numbers? Have you tried a clean script to test just Math.ceil with fixed values? – Adriano Varoli Piazza Commented Mar 23, 2011 at 18:30
  • Uhm, no, I haven't, will try that quickly. Thanks. – Anriëtte Myburgh Commented Mar 23, 2011 at 18:32
  • Thanks, that seems to do something, so obviously I need to initialize them somewhere. – Anriëtte Myburgh Commented Mar 23, 2011 at 18:36
  • It's quite possible that the variables aren't initialized or are text, and then you'd have to cast them to numbers. – Adriano Varoli Piazza Commented Mar 23, 2011 at 20:49
Add a ment  | 

3 Answers 3

Reset to default 5

Answer is yes to both your questions:

Math.ceil()

Math.round()

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards.

See also general table of Javascript patibility for different IE versions:

Seems like microsoft supports Math.ceil on all versions beginning from ie6 (msdn), maybe one of the variables use is undefined or you devide by 0 or one of the variables is not a number so the result cannot be ceiled/rounded.

IE8 actually has a fairly good debugger. I remend hitting F12 to open it, then going to the Script tab and selecting the Start Debugging button. This will let you set breakpoints along the script, letting it stop and wait for you to analyze variables as it executes at your own pace. As Adriano mentions in his ment, it's most likely an issue with one of your variables.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744399297a4572306.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信