Reputation: 31
I need to take a number like (0.25) and multiply by ten repeatedly until there are no values after the decimal point.
For example, if the number was .25
then I would need to multiply by ten repeatedly:
.25 * 10 * 10 = 25
or if the number was 1.5
1.5 * 10 = 15
What would be the best way to do this? A for loop? I know I should do something like
number = .75
for i in range(0,10):
number * 10**i = ???? (this is where I am stuck)
Upvotes: 2
Views: 159
Reputation: 578
If the input is always positive fraction (1 > x > 0), I would try this:
def fraction2int(b):
return int('{}'.format(b).replace('0.', ''))
Upvotes: 0