modf()

modf(number) Returns whole and fraction part of an input number.
modf(n)  
Retuns a tuple having two float data type elements , (fractional_part, integer_part)
import math
d=math.modf(23.45)
print(type(d)) #<class 'typle'>
print(d[0]) # 0.4499999999999993 
print(d[1]) # 23.0 

Example
import math
print(math.modf(23.45)) # (0.4499999999999993, 23.0)
print(math.modf(23))    # (0.0,23.0) 
print(math.modf(-12.34))# (-0.33999999999999986, -12.0) 
Using PI to get whole and fraction parts
import math
print(math.modf(math.pi)) # (0.14159265358979312, 3.0) 
The whole part of the input number is always float data type. To get the integer we can use math.floor().
print(math.floor(23.45)) # 23 

Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer