I have a function that takes a float as an input and the output is only the decimal part.
For example, get_decimal(4.45)
should return 0.45
, and we should only return positive figures.
I made the following code:
def get_decimal(n):
try:
return float('0.'+(str(n).split('.',1))[1])
except:
return 0
And this code almost works, but it doesn't give the whole answer.
For example get_decimal(4.566666678258757587577)
only returns:
0.566666678258757
instead of:
0.566666678258757587577
Is there a way to get the whole number?