C# Decimal Equality

Description

Decimal Equality returns a value that indicates whether two Decimal values are equal.

Syntax

Decimal.Equality has the following syntax.


public static bool operator ==(
  decimal d1,
  decimal d2
)

Parameters

Decimal.Equality has the following parameters.

  • d1 - The first value to compare.
  • d2 - The second value to compare.

Returns

Decimal.Equality method returns true if d1 and d2 are equal; otherwise, false.

Example

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


using System;/*from w ww  .  ja v a  2s .c o  m*/

public class Example
{
   public static void Main()
   {
      Decimal number1 = 16354.0695m;
      Decimal number2 = 16354.0699m;
      Console.WriteLine("{0} = {1}: {2}", number1, 
                        number2, number1 == number2);

      number1 = Decimal.Round(number1, 2);
      number2 = Decimal.Round(number2, 2);
      Console.WriteLine("{0} = {1}: {2}", number1, 
                        number2, number1 == number2);
   }
}

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