/// <summary>Returns a <see langword="Decimal" /> value that corresponds to the specified object and number format information. </summary> /// <param name="Value">Required. Object to convert to a <see langword="Decimal" /> value.</param> /// <param name="NumberFormat">A <see cref="T:System.Globalization.NumberFormatInfo" /> object that defines how numeric values are formatted and displayed, depending on the culture.</param> /// <returns>The <see langword="Decimal" /> value that corresponds to <paramref name="Value" />.</returns> public static Decimal FromObject(object Value, NumberFormatInfo NumberFormat) { if (Value == null) { return(Decimal.Zero); } IConvertible convertible = Value as IConvertible; if (convertible != null) { switch (convertible.GetTypeCode()) { case TypeCode.Boolean: return(DecimalType.FromBoolean(convertible.ToBoolean((IFormatProvider)null))); case TypeCode.Byte: return(new Decimal((int)convertible.ToByte((IFormatProvider)null))); case TypeCode.Int16: return(new Decimal((int)convertible.ToInt16((IFormatProvider)null))); case TypeCode.Int32: return(new Decimal(convertible.ToInt32((IFormatProvider)null))); case TypeCode.Int64: return(new Decimal(convertible.ToInt64((IFormatProvider)null))); case TypeCode.Single: return(new Decimal(convertible.ToSingle((IFormatProvider)null))); case TypeCode.Double: return(new Decimal(convertible.ToDouble((IFormatProvider)null))); case TypeCode.Decimal: return(convertible.ToDecimal((IFormatProvider)null)); case TypeCode.String: return(DecimalType.FromString(convertible.ToString((IFormatProvider)null), NumberFormat)); } } throw new InvalidCastException(Utils.GetResourceString("InvalidCast_FromTo", Utils.VBFriendlyName(Value), "Decimal")); }
/// <summary>Returns a <see langword="Decimal" /> value that corresponds to the specified string. </summary> /// <param name="Value">Required. String to convert to a <see langword="Decimal" /> value.</param> /// <returns>The <see langword="Decimal" /> value that corresponds to <paramref name="Value" />.</returns> public static Decimal FromString(string Value) { return(DecimalType.FromString(Value, (NumberFormatInfo)null)); }