コード例 #1
0
        public static bool TryParse(
            string txt,
            QualifiedNumber qn)
        {
            double d;

            if (txt == null)
            {
                return(false);
            }

            ParseToTextElements(txt, StaticQnte);
            qn.Qualifier = StaticQnte.Qualifier;

            if (NumberEx.DoubleTryParseEx(StaticQnte.NumberValue, out d))
            {
                qn.NumberValue = d;
            }

            else
            {
                return(false);
            }

            // todo: finish parsing stats

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Compare two values (IComparable.CompareTo)
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>

        public override int CompareTo(
            object o)
        {
// First convert o to a double value

            double compVal = NullNumber;

            if (o == null)
            {
                compVal = NullNumber;
            }

            else if (o is int)
            {
                compVal = (int)o;
            }

            else if (o is long)
            {
                compVal = (long)o;
            }

            else if (o is float)
            {
                compVal = (float)o;
            }

            else if (o is double)
            {
                compVal = (double)o;
            }

            else if (o is decimal)
            {
                compVal = decimal.ToDouble((decimal)o);
            }

            else if (o is double)
            {
                compVal = (double)o;
            }

            else if (o is string)
            {
                if (!NumberEx.DoubleTryParseEx((string)o, out compVal))
                {
                    compVal = NullNumber;
                }
            }

            else if (o is StringMx)
            {
                StringMx sx = o as StringMx;
                if (!NumberEx.DoubleTryParseEx(sx?.Value, out compVal))
                {
                    compVal = NullNumber;
                }
            }

            else if (o is MobiusDataType)
            {
                compVal = ((MobiusDataType)o).NumericValue;
            }

            else
            {
                throw new Exception("Can't compare a " + GetType().Name + " to a " + o.GetType());
            }

// Now compare compVal to this NumberMx value

            if (this.Value != NullNumber && compVal != NullNumber)             // both not null
            {
                return(this.Value.CompareTo(compVal));
            }

            else if (this.Value == NullNumber && compVal == NullNumber) // both null
            {
                return(0);                                              // say equal
            }
            else if (this.Value != NullNumber)                          // this not null, compValue is null
            {
                return(-1);                                             // indicate this is less (put non-null first)
            }
            else                                                        // compValue not null, this is null
            {
                return(1);                                              // indicate that this is greater (put non-null first)
            }
        }