4 Answers
+ 3
Unless you are going to perfom type coersion, you will not be able to _prevent_ default prescison. So, either round (without coersion) or string formatting.
+ 3
If you need more precision, you can check out the decimal library.
It works also on sololearn.
https://docs.python.org/3/library/decimal.html
+ 1
Branam ,
You can sometimes prevent the error by rearranging your formula so division happens last.
For example,
x = a / b * c # more likely to err
x = a * c / b # less likely to err
0
fairly simple to do yourself
n = input()
n_rounded = ""
for i,j in enumerate(n):
n_rounded += j
try:
if not int(j) and n.index(j,i,i+1)>n.index("."):
break
except:
pass