Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,845 questions

51,766 answers

573 users

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
...