Double - Sign
Returns a value indicating the sign of a double-precision floating-point number.
public static void Main() { string str = "{0,3} is {1} zero."; double[] values = { 7.03, 7.64, 0.12, 0.00, -0.12, -7.1, -7.6 }; foreach (double value in values) { // C# Extension Method: Double - 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 double-precision floating-point number. /// </summary> /// <param name="value">A signed 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 Double value) { return Math.Sign(value); } }