math.remainder()

Anonymous contributor
Anonymous contributor
Published Feb 26, 2024
Contribute to Docs

The `math.remainder()` method is the remainder of x divided by y. It will return a float value, representing the remainder. The remainder is the difference between `x` and the closest integer multiple of `y`.

Syntax

``````math.remainder(x,y)
``````
• `x`: It is the number to be divided.
• `y`: It is the number by which `x` is divided by.

Note: The Parameter `y` has to be a non-zero number or will return a `ValueError`.

Example

This example will return the remainder between two Integer values.

```# Import math Libraryimport math
# Return the remainder of x/yprint(math.remainder(10, 2))print(math.remainder(34, 3))
```

The output for the above code will be:

```0.01.0
```

The example below will return the remainder between two Float values.

```# Import math Libraryimport math
print(math.remainder(25.5, 5.7))print(math.remainder(58.9, 5.5))
```

The output for the above line of code will be:

```2.6999999999999993-1.6000000000000014
```

The use of multiple `Methods` can then convert the result to an Integer value.

```# Import math Libraryimport math
print(math.floor(math.remainder(25.5, 5.7)))print(math.ceil(math.remainder(25.5, 5.7)))
```

The output for the above code will be:

```23
```

Codebyte Example

The following code is runnable and demonstrates a few examples of the use of the `math.remainder()` method:

`usFavicon IconVisit uscodeHide codeCodeOutputHide outputHide outputLoading...`