I have a function that takes as a user input float parameter. I need to determine the number of digits that this parameter has to the right of the decimal place. I've tried the following but it doesn't work in the function. Any alternatives?
def x(x,y,minp):
delta = ( ( y - x)/ minp ) * 10
return delta
Essentially, I am writing a function to compute the delta of 2 values that has a multiplier associated with it. But the delta changes with the minimum increment I specify in minp
. \
So for example, if x=100, and y=90, and minp=1, then the above should equal 100. The problem arises when i have decimals for y and x.
any ideas?
EDIT:
So the problem is that if say x = 99.10
, y=99.0
, and minp=0.01
, i get 99.99999999999432
.
I tried:
delta = ( ( 99.1 - 99.0 )/ 0.01 ) * 10
dec = decimal.Decimal( 0.01 )
rounding = dec.as_tuple().exponent
round(delta,rounding)
above returns 0.0
...