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.
[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?
Post Details
- Posted
- 6 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/Python/comm...