It is pretty self-explanatory (see when pct
= 0.07) :
def what_the_foo(range_pct):
for pct in range_pct:
print("pct: %s, (pct*100): %s, int(pct * 100) : %s" %
(pct, pct*100, int(pct*100)))
range_pct
Out[9]: array([ 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1 ])
what_the_foo(range_pct)
pct: 0.01, (pct*100): 1.0, int(pct * 100) : 1
pct: 0.02, (pct*100): 2.0, int(pct * 100) : 2
pct: 0.03, (pct*100): 3.0, int(pct * 100) : 3
pct: 0.04, (pct*100): 4.0, int(pct * 100) : 4
pct: 0.05, (pct*100): 5.0, int(pct * 100) : 5
pct: 0.06, (pct*100): 6.0, int(pct * 100) : 6
pct: 0.07, (pct*100): 7.0, int(pct * 100) : 6
pct: 0.08, (pct*100): 8.0, int(pct * 100) : 8
pct: 0.09, (pct*100): 9.0, int(pct * 100) : 9
pct: 0.1, (pct*100): 10.0, int(pct * 100) : 10
I know this must be about the floating representation of 0.07, but everything seems fine outside the function :
0.07 * 100
Out[11]: 7.000000000000001
int(0.07 * 100)
Out[12]: 7
Why int(0.07 * 100)
returns 6 inside the function and 7 oustide ? Actually, why would it return 6 anyway ?