Exemplo n.º 1
0
        object TryValue(object obj)
        {
            if (obj == null)
            {
                return(null);
            }
            double?nullable = FormatConverter.TryDouble(obj, false);

            if (nullable.HasValue)
            {
                int    num2;
                long   num3;
                double d = nullable.Value;
                if (Math.Abs((double)(d - Math.Floor(d))) != 0.0)
                {
                    return(obj);
                }
                if (NumberHelper.TryInteger(d, out num2))
                {
                    return((int)num2);
                }
                if (NumberHelper.TryLong(d, out num3))
                {
                    return((long)num3);
                }
            }
            return(obj);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Parses the specified format.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <returns>Returns the value.</returns>
 public override object Parse(string s)
 {
     s = this.TrimSpecialSymbol(s);
     if ((s != null) && (s != string.Empty))
     {
         bool   flag;
         string str = NumberHelper.FixJapaneseChars(s);
         if (bool.TryParse(s, out flag))
         {
             return((bool)flag);
         }
         bool flag2 = DefaultTokens.IsDecimal(str, this.NumberFormatInfo);
         bool flag3 = str.IndexOf(DefaultTokens.ExponentialSymbol, (StringComparison)StringComparison.CurrentCultureIgnoreCase) > -1;
         bool flag4 = (str[0] == DefaultTokens.LeftParenthesis) && (str[str.Length - 1] == DefaultTokens.RightParenthesis);
         if (this.numberFormatString != null)
         {
             double num2;
             int    count = 0;
             s = this.TrimPercentSign(s, out count);
             if (this.TryParse(s, out num2, flag3 | flag4))
             {
                 if (count > 0)
                 {
                     num2 /= 100.0 * count;
                 }
                 if ((num2 != 0.0) && (Math.Abs((double)(num2 - Math.Floor(num2))) != 0.0))
                 {
                     flag2 = true;
                 }
                 if (flag3)
                 {
                     flag2 = true;
                 }
                 if (!flag2)
                 {
                     int  num3;
                     long num4;
                     if (NumberHelper.TryInteger(num2, out num3))
                     {
                         return((int)num3);
                     }
                     if (NumberHelper.TryLong(num2, out num4))
                     {
                         return((long)num4);
                     }
                 }
                 return((double)num2);
             }
         }
     }
     return(null);
 }