using System; using System.Globalization; namespace Ubisoft { /// /// Utility class for dealing with double type. /// public static class HtDouble { public static readonly IFormatProvider DefaultFormatProvider = HtTypes.DefaultFormatProvider; /// /// Converts the string representation of a number to its double-precision floating-point number equivalent. /// A return value indicates whether the conversion succeeded or failed. /// /// This method uses NumberStyles.Float and CultureInfo.InvariantCulture. /// Use this method when the string to convert comes from Content or persistence. /// /// A string containing a number to convert. /// When this method returns, contains double-precision floating-point number equivalent to the numeric of the s parameter, /// if the conversion succeeded, or zero if the conversion failed. /// The conversion fails if the s parameter is null or Empty or is not a number in a valid format. /// It also fails on .NET Framework and .NET Core 2.2 and earlier versions if s represents a number less than MinValue or /// greater than MaxValue. /// This parameter is passed uninitialized; any value originally supplied in result will be overwritten. /// /// true if s was converted successfully; otherwise, false public static bool TryParse(string s, out double result) { return TryParse(s, DefaultFormatProvider, out result); } /// /// Converts the string representation of a number to its double-precision floating-point number equivalent. /// A return value indicates whether the conversion succeeded or failed. /// /// This method uses NumberStyles.Float. /// /// A string containing a number to convert. /// An object that supplies culture-specific formatting information about s. /// When this method returns, contains the double-precision floating-point number equivalent of the s parameter, /// if the conversion succeeded, or zero if the conversion failed. /// The conversion fails if the s parameter is null or Empty or is not a number in a valid format. /// It also fails on .NET Framework and .NET Core 2.2 and earlier versions if s represents a number less than MinValue or /// greater than MaxValue. /// This parameter is passed uninitialized; any value originally supplied in result will be overwritten. /// /// true if s was converted successfully; otherwise, false public static bool TryParse(string s, IFormatProvider provider, out double result) { return double.TryParse(s, NumberStyles.Float, provider, out result); } /// /// Converts the string representation of a number to its double-precision floating-point number equivalent. /// /// This method uses NumberStyles.Float and CultureInfo.InvariantCulture. /// Use this method when the string to convert comes from Content or persistence. /// A string containing a number to convert. /// A double-precision floating-point number equivalent to the numeric value or symbol specified in s. /// or /// ArgumentNullException if s is null. /// or /// FormatException if s is not in a format compliant with CultureInfo.InvariantCulture. /// or /// OverflowException if s represents a number less than MinValue or greater than MaxValue. /// public static double Parse(string s) { return Parse(s, DefaultFormatProvider); } /// /// Converts the string representation of a number to its double-precision floating-point number equivalent. /// /// This method uses NumberStyles.Float. /// A string containing a number to convert. /// An object that supplies culture-specific formatting information about s. /// A double-precision floating-point number equivalent to the numeric value or symbol specified in s. /// or /// ArgumentNullException if s is null. /// or /// FormatException if s is not in a format compliant with CultureInfo.InvariantCulture. /// or /// OverflowException if s represents a number less than MinValue or greater than MaxValue. /// public static double Parse(string s, IFormatProvider provider) { return double.Parse(s, NumberStyles.Float, provider); } /// /// Converts the numeric value of this instance to its equivalent string representation using CultureInfo.InvariantCulture. /// /// Use this method when you need the string returned to be independent from user's culture, typically when storing persistence, which /// will be loaded by using HtDouble.Parse() or HtDouble.TryParse() methods. /// /// A double-precision floating-point number. /// The string representation of the value. public static string ToString(double value) { return value.ToString(DefaultFormatProvider); } } }