Double - IEEERemainder

Returns the remainder resulting from the division of a specified number by another specified number.

Try it

public static void Main()
{
    Console.WriteLine("{0,40}, {1,20}", "IEEERemainder", "Remainder operator");
    ShowRemainders(3, 2);
    ShowRemainders(4, 2);
    ShowRemainders(10, 3);
    ShowRemainders(11, 3);
    ShowRemainders(27, 4);
    ShowRemainders(28, 5);
    ShowRemainders(17.8, 4);
    ShowRemainders(17.8, 4.1);
    ShowRemainders(-16.3, 4.1);
    ShowRemainders(17.8, -4.1);
    ShowRemainders(-17.8, -4.1);
}

private static void ShowRemainders(double d1, double d2)
{
    // C# Extension Method: Double - IEEERemainder
    var ieeeRemainder = d1.IEEERemainder(d2);
    var remainder = d1 % d2;
    Console.WriteLine("{0,5} / {1, 5} {2,25} {3,20}", d1, d2, ieeeRemainder, remainder);
}

View Source
using System;

public static partial class Extensions
{
    /// <summary>
    ///     Returns the remainder resulting from the division of a specified number by another specified number.
    /// </summary>
    /// <param name="x">A dividend.</param>
    /// <param name="y">A divisor.</param>
    /// <returns>
    ///     A number equal to  - ( Q), where Q is the quotient of  /  rounded to the nearest integer (if  /  falls
    ///     halfway between two integers, the even integer is returned).If  - ( Q) is zero, the value +0 is returned if
    ///     is positive, or -0 if  is negative.If  = 0,  is returned.
    /// </returns>
    public static Double IEEERemainder(this Double x, Double y)
    {
        return Math.IEEERemainder(x, y);
    }
}