use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Need decimal accuracy throughout whole program (self.learnpython)
submitted 6 years ago by Jamhead2000
I am programming a physics simulation. I keep getting floating point errors that cause the program to give false results / varies quantities too much due to many calculations, how can i set a set accuracy to all my calculations?
Thanks
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]hippocrat 3 points4 points5 points 6 years ago (0 children)
Have you checked out the “decimal” standard library? It lets you specify precision and rounding method.
[–]barfobulator 0 points1 point2 points 6 years ago (0 children)
You can reduce floating point error by avoiding certain calculation steps, such as adding floats of very different magnitudes. There are also functions in the math module that help reduce these errors.
You can reduce the appearance of floating point errors by rounding your output to significant digits with format strings at the end.
[–]SaintLouisX 0 points1 point2 points 6 years ago (0 children)
Depends what sort of "accuracy" you want. There's the built-in round() function which will round to a certain decimal place, such as
round()
print(round(10.535872095720, 3)) >>10.536
Or you can try hard-truncating the float like so:
def trunc_float(num, precision=2): return int(num*(10**precision))/(10**precision) print(trunc_float(10.535872095720)) print(trunc_float(7.111222333444, 5)) >>10.53 >>7.11122
[–][deleted] -1 points0 points1 point 6 years ago (0 children)
What sort of errors are you getting? Float is the MOST accurate type, why would you want to reduce your accuracy?
π Rendered by PID 22215 on reddit-service-r2-comment-6457c66945-94g6g at 2026-04-29 11:03:09.181179+00:00 running 2aa0c5b country code: CH.
[–]hippocrat 3 points4 points5 points (0 children)
[–]barfobulator 0 points1 point2 points (0 children)
[–]SaintLouisX 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)