Math.round() and Math.floor() problem with setInterval()

50,208

When you say 'doesn't work' you mean always rounds down and keeps the value of number1 at 400 indefinitely. You need to save the rounded value to a different variable or assign it directly to your display field. :)

Share:
50,208
Sayed
Author by

Sayed

UI Designer - Developer SOreadytohelp

Updated on March 26, 2020

Comments

  • Sayed
    Sayed about 4 years

    I'm having problem with Math.round() and Math.floor() in setInterval() function by using jQuery.

    This is my code:

    var number1 = 400;
    var up_up = setInterval(
    function (){
        number1 = parseFloat(number1) + parseFloat(0.2548777);
        number1 = Math.round(number1);
        $('#number1').html(number1);
    }, 1000);
    

    The Math.round() or Math.floor() doesn't work, but when I use Math.ceil() it works fine, but I want round or floor..

    Please help