ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

IsEqualMoney

Compares two money (decimal) variables ignoring differences above 0.01. Useful for comparing two calculated decimals. 73,414.IsEqualMoney(73,41) returns true.

Source

public static partial class ExtensionMethods
{
    public static bool IsEqualMoney(this decimal money1, decimal money2)
    {
        return Math.Abs(money1 - money2) <= 0.01M;
    }
}

Example

if (faktuur.ReedsBetaaldInc.IsEqualMoney
    (faktuur.BedragTotaalInc))
return new SolidColorBrush(Colors.Green);
     else
return new SolidColorBrush(Colors.Red);

Author: Loek van den Ouweland

Submitted on: 1 okt. 2010

Language: C#

Type: System.Decimal

Views: 5328