The fmod() function - Python math module

The fmod() function from the math module of Python returns the floating point remainder of a division operation. The function is implemented as per the definition of fmod() function in the C language standard.

Math Updated 20 Aug 2021 1 min read

Overview

  • The function fmod() returns the floating point remainder of the division operation x/y of two numbers.
  • When the value of the denominator is zero the fmod() function raises an Exception stating ValueError: math domain error.

Example

python
# Example Python program that returns the floating point

            # remainder of x/y

            import math

num1 = 10.5

            num2 = 2.5

# Calculate the remainder

            rem = math.fmod(num1, num2)

            print("Remainder:")

            print(rem)

Output

Output
Remainder:

0.5