Decimal - Sign
Returns a value indicating the sign of a decimal number.
public static void Main() { string str = "{0,3} is {1} zero."; decimal[] values = { 7.03m, 7.64m, 0.12m, 0.00m, -0.12m, -7.1m, -7.6m }; foreach (decimal value in values) { // C# Extension Method: Decimal - Sign Console.WriteLine(str, value, Display(value.Sign())); } } public static String Display(int compare) { if (compare == 0) return "equal to"; else if (compare < 0) return "less than"; else return "greater than"; }
View Source
using System; public static partial class Extensions { /// <summary> /// Returns a value indicating the sign of a decimal number. /// </summary> /// <param name="value">A signed decimal number.</param> /// <returns> /// A number that indicates the sign of , as shown in the following table.Return value Meaning -1 is less than /// zero. 0 is equal to zero. 1 is greater than zero. /// </returns> public static Int32 Sign(this Decimal value) { return Math.Sign(value); } }