/    Sign up×
Community /Pin to ProfileBookmark

totaal = 0.1 + 1.1;

gives a result of 1.20000000000000002

why not just 1.2 ?

Does anybody know why the result is not what I expect? ?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsMar 31.2005 — due to rounding errors on floating point calculations with a 32 bit machine
Copy linkTweet thisAlerts:
@CharlesMar 31.2005 — Contrary to what one might assume, computers are simply bad at math. But if you round everyting off to two or three decimal places, things usually work out alright.
Copy linkTweet thisAlerts:
@KorMar 31.2005 — Computers are not good at [b]decimal[/b] math operations, as they convert first to binary, than calculate, than reconvert to decimal. Some floated numbers are not to be exactly converted into binary, thus small approximate round occures. Sometimes those small rounds added and the result is bizzare, from a decimal point of view.

See also the thread:

http://www.webdeveloper.com/forum/showthread.php?t=56278
×

Success!

Help @danielb 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 5.17,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...