Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Python 3 Floats acting strangely
Post Body

[edit] Solved! I need to be utilizing Python's Decimal module for more precision than simple floats will allow. Thank you to all who helped me here! I'm new to this end of programming but eager to learn proper practice!


Hey everyone! Hope your projects are going well!

So... below is a little test code I ran because I have been getting some funny outputs from float math and now I'm suuuuper confused about what's happening.

num1 = float(123456789.123456789)
print(num1)
# Output >>> 123456789.12345679
print(f'{num1:.100g}')
# Output >>> 123456789.12345679104328155517578125

num2 = float(12345678987654321.12345678987654321)
print(num2)
# Output >>> 1.2345678987654322e 16
print(f'{num2:.100g}')
# Output >>> 12345678987654322

Why is it rounding when I simply PRINT a straight up float value? Even when formatting to decimals its rounding whole if the decimal is super long to begin with. No math involved here and yet not getting the same number for each... and I need up to 10 decimals to be accurate for my project. Any ideas how I can more accurately display my float values?

Author
User Disabled
Account Strength
0%
Disabled 5 months ago
Account Age
6 years
Verified Email
Yes
Verified Flair
No
Total Karma
744
Link Karma
526
Comment Karma
203
Profile updated: 3 days ago
Posts updated: 8 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
6 years ago