Very simple, I want to round my 'base_price' and 'entry' with the precision, here 0.00001. It doesn't work because it converts it to a scientific number. How do I do this; I have been stuck for 1 hour.
Some post says to use output="{:.9f}".format(num)
but it adds some zero after the last 1.
It work with precision = str(0.0001)
but start from 4 zeros after the dot, it change to scientific numbers and digit = precision[::-1].find('.')
doesn't work with scientific numbers.
precision = str(0.00001) #5 decimals after the dot
print(precision)
base_price=0.0314858333
entry=0.031525
digit = precision[::-1].find('.')
entry_price = float(round(float(entry), digit))
base_price = float(round(float(base_price), digit))
print(entry_price,base_price)
Expected result:
base_price=0.03148 #5 decimals after the dot
entry=0.03152 #5 decimals after the dot
source https://stackoverflow.com/questions/73901048/python-rounding-does-not-work-because-of-scientific-number
Comments
Post a Comment