/// <summary> /// Compares this with the specified value. Returns 1 if the other /// item is greater than this value, 0 if they are equal and -1 if /// the other value is less than this value. /// </summary> /// <param name="other">The value to be tested.</param> /// <returns>An integer: 1 if the other /// item is greater than this value, 0 if they are equal and -1 if /// the other value is less than this value. </returns> public int CompareTo(object other) { if (Global.IsDouble(other) == false) { throw new NonNumericException("other"); } return(_value.CompareTo(Global.GetDouble(other))); }
/// <summary> /// Initializes a new instance of the <see cref="Number"/> struct. /// Creates a value from an object /// </summary> /// <param name="value">A numeric value that is, or can be parsed to a numeric value.</param> /// <exception cref="NonNumericException">Not Numeric</exception> public Number(object value) { if (Global.IsShort(value)) { _value = Global.GetDouble(value); SignificantFigures = 5; DecimalsCount = 0; Format = NumberFormat.General; _hasValue = true; return; } if (Global.IsInteger(value)) { _value = Global.GetDouble(value); SignificantFigures = 10; DecimalsCount = 0; Format = NumberFormat.General; _hasValue = true; return; } if (Global.IsFloat(value)) { _value = Global.GetDouble(value); SignificantFigures = 8; DecimalsCount = 7; Format = NumberFormat.General; _hasValue = true; return; } if (Global.IsDouble(value)) { // doubles can have 16 digits, so in scientific notation _value = Global.GetDouble(value); SignificantFigures = 16; DecimalsCount = 15; Format = NumberFormat.General; _hasValue = true; return; } throw new NonNumericException("value"); }