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

I have a problem with Math.round () and Math.floor () in the setInterval () function 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); 

Math.round () or Math.floor () does not work, but when I use Math.ceil (), it works fine, but I want round or floor.

Please, help

+4
source share
1 answer

When you say "does not work", you mean that it always rounds and stores the value of number1 by 400 unlimited. You need to save the rounded value to another variable or assign it directly to the display field. :)

+6
source

Source: https://habr.com/ru/post/1345282/


All Articles