AdamWhiteHat / BigDecimal

An arbitrary-precision decimal (base 10) floating-point number class. Over 2.5 million downloads on NuGet!
MIT License
53 stars 15 forks source link

BUG: incorrect parsing with non-dot decimal separator #35

Closed Bykiev closed 7 months ago

Bykiev commented 7 months ago

Description When rounding the value with culture where decimal separator is comma an error has occured.

Error/Exception Message System.FormatException: "The value could not be parsed."

в System.Numerics.BigNumber.ParseBigInteger(ReadOnlySpan`1 value, NumberStyles style, NumberFormatInfo info)
   в System.Numerics.BigNumber.ParseBigInteger(String value, NumberStyles style, NumberFormatInfo info)
   в ExtendedNumerics.BigDecimal.GetWholePart()
   в ExtendedNumerics.BigDecimal.Round(BigDecimal value, MidpointRounding mode)

Expected Behavior The value should be correctly parsed

Actual Behavior An error has occured: System.FormatException: "The value could not be parsed."

Steps To Reproduce

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator = ",";

var res = new BigDecimal(17.56);
var e = BigDecimal.Round(res, MidpointRounding.AwayFromZero);
Bykiev commented 7 months ago

I'm working on this, will create PR soon