precision = 2
number = 31684.28
result = Decimal(number) - Decimal(10 ** -precision)
print(result)
Desired output:
31684.27
Actual output:
31684.26999999999883584657356
What I try to do is to subtract 0.01 from number.
You have to make the values with Decimal(...) not the output. So try this:
from decimal import Decimal
precision = 2
number = 31684.28
result = number - float(10 ** Decimal(-precision))
print(result)
Output:
31684.27
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With