On Monday 31 May 2004 06:22 pm, Norlin Abd Rahim wrote: > the number actually comes from multiplication between 237.50 and 4.762 > which will get 1130.975. So it suppose to be 1130.98 isnt it if it'll get > rounded to 2 decimal places. But... Due to the wonders and inaccuracies of binary floating point representations on digital computers, 4.762 can not be represented EXACTLY. The closest it can get is 4.7619999999999996, and that's where you're inaccuracy comes from. In the following interactive python session, the values printed out are printed out to their full precision (that's a often misunderstood feature of the python interactive mode). You can see where the floating point inaccuracies are introduced. >>> 237.50 237.5 >>> 4.762 4.7619999999999996 >>> 237.50 * 4.762 1130.9749999999999 >>> Just for clarification .. This is NOT a problem with Python, but is a feature of the binary representation of floating point numbers and can be found on all computers and in all programming languages. Gary Herron
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4