HP Forums

Full Version: Python round() broken
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is it just my G2 to show this error in Python?

round(3/7,6) ==> 0.4285709999999999 (if I counted the 9s correctly)
should be 0.2428571
similar error with
round(5/7,6)
round(3/11,6)
round(5/11,6
round(7/11,6)

previously in my post a first digit "2"crept in inadvertently

The virtual calculator 64bit doesn't show this behavior.

Günter

PS: of course reported to calcbeta too
(04-17-2021 07:08 PM)Guenter Schink Wrote: [ -> ]Is it just my G2 to show this error in Python?

round(3/7,6) ==> 0.24285709999999999 (if I counted the 9s correctly)
should be 0.2428571

Wow! Your calculator is really off! I get

0.4285709999999999

Smile
(04-17-2021 08:48 PM)toml_12953 Wrote: [ -> ]
(04-17-2021 07:08 PM)Guenter Schink Wrote: [ -> ]Is it just my G2 to show this error in Python?

round(3/7,6) ==> 0.24285709999999999 (if I counted the 9s correctly)
should be 0.2428571

Wow! Your calculator is really off! I get

0.4285709999999999

Smile

grrr.. typo - first digit "2" shouldn't be there. But what would you expect with rounding to 6 digits? The result should be 0.428571

Günter
(04-17-2021 11:10 PM)Guenter Schink Wrote: [ -> ]
(04-17-2021 08:48 PM)toml_12953 Wrote: [ -> ]Wow! Your calculator is really off! I get

0.4285709999999999

Smile

grrr.. typo - first digit "2" shouldn't be there. But what would you expect with rounding to 6 digits? The result should be 0.428571

Günter
Yes, You added an extra 2. I knew that it wasn't your calculator, hence the smiley.
Hello,

I have literally NO clue as to what is going on there!
Works on emulator, works on prime G1... but prime G2 fails!

Something buried deep in the float library or something like that?

Note that Python uses doubles... As such, these are binary numbers... not BCD... so things like rounding will/Can yeild unexpected results...

Cyrille
Reference URL's