Rounding Values in Python when Returning from a Function
usecase
The concern is documenting the how to round the values, coming from writing the procedure for finding square root that returns saying
Fail: assert 3.00009155413138 == 3
1. steps
- there is a lot of rounding strategies, at the moment I am using the
truncate
method
def truncate(n, decimals=3):
multiplier = 10 ** decimals
return int(n * multiplier) / multiplier
3.00009155413138
→3.000
and the test passes there