C# Decimal Modulus

Description

Decimal Modulus returns the remainder resulting from dividing two specified Decimal values.

Syntax

Decimal.Modulus has the following syntax.


public static decimal operator %(
  decimal d1,
  decimal d2
)

Parameters

Decimal.Modulus has the following parameters.

  • d1 - The dividend.
  • d2 - The divisor.

Returns

Decimal.Modulus method returns The remainder resulting from dividing d1 by d2.

Example

The Modulus method defines the operation of the modulus operator for Decimal values. It enables code such as the following:


using System;// w w w. ja  va2s. c  o  m

public class Example
{
   public static void Main()
   {
      Decimal number1 = 16.8m;
      Decimal number2 = 4.1m;
      Decimal number3 = number1 % number2;
      Console.WriteLine(number3);
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version