/// <summary> /// Converts the string representation of a number to its double-precision floating-point number equivalent. /// </summary> /// <param name="value">A string that contains a number to convert.</param> /// <param name="CatchError">Catch Error?</param> /// <param name="DefaultValue">The default value returned if the conversion fails.</param> public static double ToDouble(this string value, bool CatchError = true, double DefaultValue = 0.0) { try { return double.Parse(value.ConvertStringCulture()); } catch (Exception ex) { if (CatchError) ex.CatchError(); return DefaultValue; } }
/// <summary> /// Converts the string representation of a number to its double-precision floating-point number equivalent. /// </summary> /// <param name="value">A string that contains a number to convert.</param> /// <param name="DefaultValue">The default value returned if the conversion fails.</param> public static double ToDouble(this string value, double DefaultValue = 0.0) { try { return double.Parse(value.ConvertStringCulture()); } catch (Exception) { return DefaultValue; } }
/// <summary> /// Converts the string representation of a number to its <see cref="decimal"/> equivalent. /// </summary> /// <param name="value">The string representation of the number to convert.</param> /// <param name="CatchError">Catch Error?</param> /// <param name="DefaultValue">The default value returned if the conversion fails.</param> public static decimal ToDecimal(this string value, bool CatchError = true, decimal DefaultValue = 0.0m) { try { return decimal.Parse(value.ConvertStringCulture()); } catch (Exception ex) { if (CatchError) ex.CatchError(); return DefaultValue; } }
/// <summary> /// Converts the string representation of a number to its <see cref="decimal"/> equivalent. /// </summary> /// <param name="value">The string representation of the number to convert.</param> /// <param name="DefaultValue">The default value returned if the conversion fails.</param> public static decimal ToDecimal(this string value, decimal DefaultValue = 0) { try { return decimal.Parse(value.ConvertStringCulture()); } catch (Exception) { return DefaultValue; } }
/// <summary> /// Converts the string representation of a number to its <see cref="byte"/> equivalent. /// </summary> /// <param name="value">A string that contains a number to convert. The string is interpreted using the <see cref="NumberStyles.Integer"/> style.</param> /// <param name="DefaultValue">The default value returned if the conversion fails.</param> public static byte ToByte(this string value, byte DefaultValue = 0) { try { return byte.Parse(value.ConvertStringCulture()); } catch (Exception) { return DefaultValue; } }
/// <summary> /// Converts the string representation of a number to its <see cref="byte"/> equivalent. /// </summary> /// <param name="value">A string that contains a number to convert. The string is interpreted using the <see cref="NumberStyles.Integer"/> style.</param> /// <param name="CatchError">Catch Error?</param> /// <param name="DefaultValue">The default value returned if the conversion fails.</param> public static byte ToByte(this string value, bool CatchError = true, byte DefaultValue = 0) { try { return byte.Parse(value.ConvertStringCulture()); } catch (Exception ex) { if (CatchError) ex.CatchError(); return DefaultValue; } }
/// <summary> /// Convert string to long type. /// </summary> /// <param name="value">The string to convert.</param> public static long Tolong(this string value) { try { return long.Parse(value.ConvertStringCulture()); } catch (Exception ex) { ex.CatchError(); } return 0; }
/// <summary> /// Convert string to decimal type. /// </summary> /// <param name="value">The string to convert.</param> public static decimal Todecimal(this string value) { try { return decimal.Parse(value.ConvertStringCulture()); } catch (Exception ex) { ex.CatchError(); } return 0; }
/// <summary> /// Convert string to bool type. /// </summary> /// <param name="value">The string value to convert.</param> /// <param name="DefaultValue">The default value returned if the conversion fails.</param> public static bool ToBool(this string value, bool DefaultValue = true) { try { if (int.Parse(value.ConvertStringCulture()) > 0) return true; else return false; } catch (Exception) { if (string.Equals(value, "true", StringComparison.OrdinalIgnoreCase)) return true; else if (string.Equals(value, "false", StringComparison.OrdinalIgnoreCase)) return false; else return DefaultValue; } }
/// <summary> /// Converts the string representation of a number to its 16-bit unsigned integer equivalent. /// </summary> /// <param name="value">A string that represents the number to convert.</param> /// <param name="CatchError">Catch Error?</param> /// <param name="DefaultValue">The default value returned if the conversion fails.</param> public static ushort ToUshort(this string value, bool CatchError = true, ushort DefaultValue = 0) { try { return ushort.Parse(value.ConvertStringCulture()); } catch (Exception ex) { if (CatchError) ex.CatchError(); return DefaultValue; } }
/// <summary> /// Converts the string representation of a number to its 64-bit unsigned integer equivalent. /// </summary> /// <param name="value">A string that represents the number to convert.</param> /// <param name="DefaultValue">The default value returned if the conversion fails.</param> public static ulong ToUlong(this string value, ulong DefaultValue = 0) { try { return ulong.Parse(value.ConvertStringCulture()); } catch (Exception) { return DefaultValue; } }
/// <summary> /// Converts the string representation of a number to its 64-bit signed integer equivalent. /// </summary> /// <param name="value">A string containing a number to convert.</param> /// <param name="CatchError">Catch Error?</param> /// <param name="DefaultValue">The default value returned if the conversion fails.</param> public static long ToLong(this string value, bool CatchError = true, long DefaultValue = 0) { try { return long.Parse(value.ConvertStringCulture()); } catch (Exception ex) { if (CatchError) ex.CatchError(); return DefaultValue; } }
/// <summary> /// Converts the string representation of a number to its single-precision floating-point number equivalent. /// </summary> /// <param name="value">A string that contains a number to convert.</param> /// <param name="CatchError">Catch Error?</param> /// <param name="DefaultValue">The default value returned if the conversion fails.</param> public static float ToSingle(this string value, bool CatchError = true, float DefaultValue = 0.0f) { try { return float.Parse(value.ConvertStringCulture()); } catch (Exception ex) { if (CatchError) ex.CatchError(); return DefaultValue; } }
/// <summary> /// Converts the string representation of a number to its single-precision floating-point number equivalent. /// </summary> /// <param name="value">A string that contains a number to convert.</param> /// <param name="DefaultValue">The default value returned if the conversion fails.</param> public static float ToFloat(this string value, float DefaultValue = 0) { try { return float.Parse(value.ConvertStringCulture()); } catch (Exception) { return DefaultValue; } }
/// <summary> /// Converts the string representation of a number to its 16-bit unsigned integer equivalent. /// </summary> /// <param name="value">A string that represents the number to convert.</param> /// <param name="DefaultValue">The default value returned if the conversion fails.</param> public static ushort ToUshort(this string value, ushort DefaultValue = 0) { try { return ushort.Parse(value.ConvertStringCulture()); } catch (Exception) { return DefaultValue; } }
/// <summary> /// Convert string to sbyte type. /// </summary> /// <param name="value">The string to convert.</param> public static sbyte Tosbyte(this string value) { try { return sbyte.Parse(value.ConvertStringCulture()); } catch (Exception ex) { ex.CatchError(); } return 0; }
/// <summary> /// Convert string to ushort type. /// </summary> /// <param name="value">The string to convert.</param> public static ushort Toushort(this string value) { try { return ushort.Parse(value.ConvertStringCulture()); } catch (Exception ex) { ex.CatchError(); } return 0; }
/// <summary> /// Converts the string representation of a number to its 32-bit signed integer equivalent. /// </summary> /// <param name="value">A string containing a number to convert.</param> /// <param name="DefaultValue">The default value returned if the conversion fails.</param> public static int ToInt(this string value, int DefaultValue = 0) { try { return int.Parse(value.ConvertStringCulture()); } catch (Exception) { return DefaultValue; } }