Python modf () function
description
modf () method returns the integer part and the fractional part of x, sign of the value of the two parts with the same x, the integer part in floating-point representation.
grammar
The following is the syntax modf () method:
import math math.modf( x )
Note: modf () is not directly accessible, you need to import math module, invoke the method through static object.
parameter
- x - numeric expression.
return value
Returns the integer part and the fractional part of x,Examples
The following shows an example of using modf () method:
#!/usr/bin/python import math # This will import math module print "math.modf(100.12) : ", math.modf(100.12) print "math.modf(100.72) : ", math.modf(100.72) print "math.modf(119L) : ", math.modf(119L) print "math.modf(math.pi) : ", math.modf(math.pi)
After running the above example output is:
math.modf(100.12) : (0.12000000000000455, 100.0) math.modf(100.72) : (0.71999999999999886, 100.0) math.modf(119L) : (0.0, 119.0) math.modf(math.pi) : (0.14159265358979312, 3.0)