public static decimal ObjectToDecimal(object obj, decimal defaultVal = 0M) { if (obj is null) { return(defaultVal); } if (obj is decimal myself) { return(myself); } if (obj is string str) { return(StringToDecimal(str, defaultVal)); } str = obj.ToString(); if (StringDecimalDeterminer.Is(str)) { return(StringToDecimal(str, defaultVal)); } try { return(Convert.ToDecimal(obj)); } catch { return(defaultVal); } }
public static decimal?StringToNullableDecimal(string str) { if (StringDecimalDeterminer.Is(str)) { return(StringDecimalDeterminer.To(str)); } return(null); }
public static bool __numericIs(string s, Type type, Action <object> action, NumberStyles?numberStyle, IFormatProvider provider) => type == TypeClass.ByteClazz && StringByteDeterminer.Is(s, numberStyle ?? INT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <byte>(action)) || type == TypeClass.SByteClazz && StringSByteDeterminer.Is(s, numberStyle ?? INT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <sbyte>(action)) || type == TypeClass.Int16Clazz && StringShortDeterminer.Is(s, numberStyle ?? INT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <short>(action)) || type == TypeClass.UInt16Clazz && StringUShortDeterminer.Is(s, numberStyle ?? INT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <ushort>(action)) || type == TypeClass.Int32Clazz && StringIntDeterminer.Is(s, numberStyle ?? INT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <int>(action)) || type == TypeClass.UInt32Clazz && StringUIntDeterminer.Is(s, numberStyle ?? INT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <uint>(action)) || type == TypeClass.Int64Clazz && StringLongDeterminer.Is(s, numberStyle ?? INT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <long>(action)) || type == TypeClass.UInt64Clazz && StringULongDeterminer.Is(s, numberStyle ?? INT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <ulong>(action)) || type == TypeClass.FloatClazz && StringFloatDeterminer.Is(s, numberStyle ?? FLT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <float>(action)) || type == TypeClass.DoubleClazz && StringDoubleDeterminer.Is(s, numberStyle ?? FLT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <double>(action)) || type == TypeClass.DecimalClazz && StringDecimalDeterminer.Is(s, numberStyle ?? DEM_NUMBER_STYLE, provider, ValueConverter.ConvertAct <decimal>(action));
protected override bool IsValidImpl(object value) { if (VerifiableMember.MemberType.IsNumeric(_isOptions)) { return(true); } if (value is string strValue) { return(StringDecimalDeterminer.Is(strValue)); } return(StringDecimalDeterminer.Is(value.ToString())); }
/// <summary> /// Is decimal /// </summary> /// <param name="str"></param> /// <returns></returns> public static bool IsDecimal(this string str) => StringDecimalDeterminer.Is(str);
/// <summary> /// To judge whether the string is numeric or not. /// </summary> /// <param name="str"></param> /// <returns></returns> public static bool IsNumeric(string str) => StringDecimalDeterminer.Is(str);