How to get the numbers after decimal point from float number in Python

5 Answers

0 votes
import math

f = 234.872

mf = math.modf(f) 

print(mf[0])




'''
run:

0.8720000000000141

'''

 



answered Aug 29, 2019 by avibootz
0 votes
f = 234.872

fraction = str(f - int(f))
print(fraction)

fraction = str(f - int(f))[1:]
print(fraction)



'''
run:

0.8720000000000141
.8720000000000141

'''

 



answered Aug 29, 2019 by avibootz
0 votes
f = 234.872

fraction = f % 1

print(fraction)



'''
run:

0.8720000000000141

'''

 



answered Aug 29, 2019 by avibootz
0 votes
import math
 
f = 234.872
 
fraction, whole = math.modf(f)
 
print(fraction)
 
 
 
 
'''
run:
 
0.8720000000000141
 
'''

 



answered Aug 29, 2019 by avibootz
0 votes
import math
 
f = 234.872
 
fraction = f - int(f)
 
print(fraction)
 
 
 
 
'''
run:
 
0.8720000000000141
 
'''

 



answered Aug 29, 2019 by avibootz
...