How to break a floating point into an integral and a fractional parts in Python

2 Answers

0 votes
import math

print("math.modf(10.13) = ", math.modf(10.13))
print("math.modf(10.87) = ", math.modf(10.87))
print("math.modf(math.pi) = ", math.modf(math.pi))


'''
run:

math.modf(10.13) =  (0.13000000000000078, 10.0)
math.modf(10.87) =  (0.8699999999999992, 10.0)
math.modf(math.pi) =  (0.14159265358979312, 3.0)

'''

 



answered Oct 16, 2017 by avibootz
0 votes
import math

tuple_modf = math.modf(10.13)

print(tuple_modf)
print(tuple_modf[0])
print(tuple_modf[1])


'''
run:

(0.13000000000000078, 10.0)
0.13000000000000078
10.0

'''

 



answered Oct 16, 2017 by avibootz
...