/    Sign up×
Community /Pin to ProfileBookmark

Recursively adding 0.1 error?

Hi, I have a count up script where I count up from 0 seconds to 2 minutes. If it’s below 60 seconds, I want it to count up from 1/10th of a second each time, so 0.1, 0.2…59.1,59.2 but when I add 0.1 to the current number and run it again, sometimes it goes to such things as 0.1000000000038 or something of that sort.

Has anyone had this type of problem before? What should I do? I tried putting ParseFloat() but that’s not working.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@NedalsDec 30.2005 — Welcome to the world of converting 'float' to binary....

If you need to display the number try...

num.toFixed(n); where n is the number of decimal places.
×

Success!

Help @Browner8 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...