Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

Decimal.Remainder Method

Computes the remainder after dividing two Decimal values.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
public static decimal Remainder(
	decimal d1,
	decimal d2
)

Parameters

d1
Type: System.Decimal

The dividend.

d2
Type: System.Decimal

The divisor.

Return Value

Type: System.Decimal
The remainder after dividing d1 by d2.
ExceptionCondition
DivideByZeroException

d2 is zero.

OverflowException

The return value is less than MinValue or greater than MaxValue.

The following example uses the Remainder method to calculate the remainder in a series of division operations.

using System;

public class Example
{
    public static void Main()
    {
        // Create parallel arrays of Decimals to use as the dividend and divisor.
        Decimal[] dividends = { 79m, 1000m, -1000m, 123m, 1234567800000m,
                                1234.0123m };
        Decimal[] divisors = { 11m, 7m, 7m, .00123m, 0.12345678m, 1234.5678m };

        for (int ctr = 0; ctr < dividends.Length; ctr++) 
        {
           Decimal dividend = dividends[ctr];
           Decimal divisor = divisors[ctr];
           Console.WriteLine("{0:N3} / {1:N3} = {2:N3} Remainder {3:N3}", dividend,
                             divisor, Decimal.Divide(dividend, divisor),
                             Decimal.Remainder(dividend, divisor)); 
        }
    }
} 
// The example displays the following output: 
//       79.000 / 11.000 = 7.182 Remainder 2.000 
//       1,000.000 / 7.000 = 142.857 Remainder 6.000 
//       -1,000.000 / 7.000 = -142.857 Remainder -6.000 
//       123.000 / 0.001 = 100,000.000 Remainder 0.000 
//       1,234,567,800,000.000 / 0.123 = 10,000,000,000,000.000 Remainder 0.000 
//       1,234.012 / 1,234.568 = 1.000 Remainder 1,234.012

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.