The modf method of the math module

The modf method of the math module returns a tuple consisting of the fractional and integer parts of the given number.

Syntax

pythonimport math

math.modf(number)

Example

Let's find out the fractional and integer parts of the number 20:

pythonimport math

print(math.modf(20))

Result of code execution:

python(0.0, 20.0)

Example

Now let's apply the modf method to the number 20.56:

pythonimport math

print(math.modf(20.56))

Result of code execution:

python(0.5599999999999987, 20.0)

See also

  • function round,
    which rounds off the number
  • method floor of module math,
    which rounds a number down
  • method ceil of module math,
    which rounds a number up