AdamWhiteHat / BigDecimal

An arbitrary-precision decimal (base 10) floating-point number class.
MIT License
47 stars 15 forks source link

Parse(Double input) fails , if CurrentCulture has NumberFormat with 'comma' instead of 'dot' #16

Closed Degot closed 9 months ago

Degot commented 10 months ago

Hello,

BigDecimal Parse(Double input) => Parse(input.ToString(CultureInfo.CurrentCulture)); uses CurrentCulture to convert double into string, while next step uses BigDecimalNumberFormatInfo, which is InvariantCulture: public static BigDecimal Parse(String input) { return Parse(input, BigDecimalNumberFormatInfo); }

So, If CurrentCulture's NumberFormat is not similar to InvarantCulture, Parse + all releated tests will fail. Example: new CultureInfo("ru-RU") has 'comma' for decimal point.

AdamWhiteHat commented 9 months ago

Wow. Good catch. This same bug also existed in my BigRational library, as they share many of the same design patterns.

So thank you for that.

I pushed a new version/build of this library that includes these changes to NuGet, version 2023.1000.3.328.

Thanks for your interest in my library and for your contributions.

Feel free to close this ticket if you are satisfied, otherwise Ill swing back around in a week or so and close it if I hear nothing further from you. .

Degot commented 9 months ago

Fixed. Thank you.