Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 465
Sayed Avatar asked Mar 25 '11 20:03

Sayed


Video Answer


1 Answers

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. :)

like image 58
RSG Avatar answered Sep 22 '22 14:09

RSG