/// <summary>Returns a <see langword="Single" /> value that corresponds to the specified string and number format information. </summary> /// <param name="Value">Required. String to convert to a <see langword="Single" /> 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="Single" /> value corresponding to <paramref name="Value" />.</returns> public static float FromString(string Value, NumberFormatInfo NumberFormat) { if (Value == null) { return(0.0f); } try { long i64Value = 0; if (Utils.IsHexOrOctValue(Value, ref i64Value)) { return((float)i64Value); } double d = DoubleType.Parse(Value, NumberFormat); if ((d < -3.40282346638529E+38 || d > 3.40282346638529E+38) && !double.IsInfinity(d)) { throw new OverflowException(); } return((float)d); } catch (FormatException ex) { throw new InvalidCastException(Utils.GetResourceString("InvalidCast_FromStringTo", Strings.Left(Value, 32), "Single"), (Exception)ex); } }
/// <summary>Returns a <see langword="Boolean" /> value that corresponds to the specified string. </summary> /// <param name="Value">Required. String to convert to a <see langword="Boolean" /> value.</param> /// <returns>The <see langword="Boolean" /> value that corresponds to <paramref name="Value" />.</returns> public static bool FromString(string Value) { if (Value == null) { Value = ""; } try { CultureInfo cultureInfo = Utils.GetCultureInfo(); if (string.Compare(Value, bool.FalseString, true, cultureInfo) == 0) { return(false); } if (string.Compare(Value, bool.TrueString, true, cultureInfo) == 0) { return(true); } long i64Value = 0; if (Utils.IsHexOrOctValue(Value, ref i64Value)) { return((ulong)i64Value > 0UL); } return(DoubleType.Parse(Value) != 0.0); } catch (FormatException ex) { throw new InvalidCastException(Utils.GetResourceString("InvalidCast_FromStringTo", Strings.Left(Value, 32), "Boolean"), (Exception)ex); } }
/// <summary>Returns a <see langword="Byte" /> value that corresponds to the specified string. </summary> /// <param name="Value">Required. String to convert to a <see langword="Byte" /> value.</param> /// <returns>The <see langword="Byte" /> value that corresponds to <paramref name="Value" />.</returns> public static byte FromString(string Value) { if (Value == null) { return(0); } try { long i64Value = 0; if (Utils.IsHexOrOctValue(Value, ref i64Value)) { return(checked ((byte)i64Value)); } return(checked ((byte)Math.Round(DoubleType.Parse(Value)))); } catch (FormatException ex) { throw new InvalidCastException(Utils.GetResourceString("InvalidCast_FromStringTo", Strings.Left(Value, 32), "Byte"), (Exception)ex); } }
/// <summary>Returns a <see langword="Double" /> value that corresponds to the specified string and number format information. </summary> /// <param name="Value">Required. String to convert to a <see langword="Double" /> 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="Double" /> value corresponding to <paramref name="Value" />.</returns> public static double FromString(string Value, NumberFormatInfo NumberFormat) { if (Value == null) { return(0.0); } try { long i64Value = 0; if (Utils.IsHexOrOctValue(Value, ref i64Value)) { return((double)i64Value); } return(DoubleType.Parse(Value, NumberFormat)); } catch (FormatException ex) { throw new InvalidCastException(Utils.GetResourceString("InvalidCast_FromStringTo", Strings.Left(Value, 32), "Double"), (Exception)ex); } }
/// <summary>Returns a <see langword="Double" /> value that corresponds to the specified string. </summary> /// <param name="Value">Required. String to convert to a <see langword="Double" /> value.</param> /// <returns>The <see langword="Double" /> value corresponding to <paramref name="Value" />.</returns> public static double Parse(string Value) { return(DoubleType.Parse(Value, (NumberFormatInfo)null)); }