Exemple #1
0
        public static Decimal?ToDecimalNullable(this String Expr, String DecimalSeparator = ".")
        {
            Decimal?result = null;

            if (Expr.IsNullOrEmpty())
            {
                return(result);
            }

            NumberFormatInfo nfi = NumberFormatInfoEx.GetNumberFormatInfo(DecimalSeparator);

            Decimal newDecimal;

            Char[] AllowedChars = DecimalSeparator.IsNullOrEmpty() ? null : FloatingNumberChars(DecimalSeparator);

            Expr = Expr.OnlyNumbers(AllowedChars);

            if (Decimal.TryParse(Expr, NumberStyles.Any, nfi, out newDecimal))
            {
                result = newDecimal;
            }

            return(result);
        }
Exemple #2
0
        public static Single?ToSingleNullable(this String Expr, String DecimalSeparator = ".")
        {
            Single?result = null;

            if (Expr.IsNullOrEmpty())
            {
                return(result);
            }

            NumberFormatInfo nfi = NumberFormatInfoEx.GetNumberFormatInfo(DecimalSeparator);

            Single newSingle;

            Char[] AllowedChars = DecimalSeparator.IsNullOrEmpty() ? null : FloatingNumberChars(DecimalSeparator);

            Expr = Expr.ToLower().OnlyNumbers(AllowedChars);

            if (Single.TryParse(Expr, NumberStyles.Any, nfi, out newSingle))
            {
                result = newSingle;
            }

            return(result);
        }