Facebook Page Twitter Page LinkedIn Page
× C# Tutorial C# Advanced C# Resources


The C# Math IEEERemainder() method is used to compute the remainder operation on two arguments. The remainder can be expressed as follows:

Remainder = x - y * Q, where Q is the quotient of x/y rounded to the nearest integer. If x/y falls exactly at the midway between two integers, the even integer is returned.

In special cases it returns the following:

  • If y is zero, the method returns NaN.
  • If x - y * Q is zero, the method returns +0 if x is positive and -0 if x is negative.

Syntax

public static double IEEERemainder (double x, double y);

Parameters

x Specify the dividend.
y Specify the divisor.

Return Value

Returns the remainder when x is divided by y.

Example:

In the below example, IEEERemainder() method is used to calculate the remainder operation on two given arguments.

using System;

class MyProgram {
  static void Main(string[] args) {
    Console.WriteLine(Math.IEEERemainder(10, 4)); 
    Console.WriteLine(Math.IEEERemainder(14, 4)); 
    Console.WriteLine(Math.IEEERemainder(60.8, 18.1));  
  }
}

The output of the above code will be:

2
-2
6.499999999999993

❮ C# Math Methods

5