Reply to post: Re: Aproximate

Come mobile users, gather round and learn how to add up

Anonymous Coward
Anonymous Coward

Re: Aproximate

While mathematically speaking, 3.999999.... == 4, using a computer to perform a comparison will indicate a difference. (After all, computers can't do infinite-precision floating point...) So, if your code contains if (x==4), and x=3.99999999999, then the result is 'false', not 'true'. It's always best to round to a couple decimal places beyond the smallest expected difference (if your values are 3.5 to 4.5, round to 3.9999) and THEN do the comparison.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon