You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parse/TryParse ignore the IFormatProvider, so a value formatted with ToString(culture) cannot be parsed back with the same culture #106
Formatting honours the culture. TryWriteDigits (PreciseNumber/PreciseNumber.cs:~1300) writes numberFormat.NumberDecimalSeparator and numberFormat.NegativeSign from the provider.
Parse(ReadOnlySpan<char>, NumberStyles, IFormatProvider?) (PreciseNumber/PreciseNumber.cs:1114) never reads either style or provider. It hard-codes '.' as the decimal separator and '-' as the sign, and it rejects every other character. The INumberBase overloads pass NumberStyles.Any by default, but a leading +, surrounding whitespace and group separators are all rejected anyway.
The IParsable/ISpanParsable contract is that the provider supplies culture-specific formatting. Every BCL numeric type honours it, and this type's own ToString(provider) does too.
The same happens with fr-FR ("-0,25"). Any application running under a comma-decimal culture that persists or displays values with ToString(CultureInfo.CurrentCulture) and reads them back with Parse(..., CultureInfo.CurrentCulture) fails.
Suggested fix
Resolve NumberFormatInfo.GetInstance(provider) in Parse, and:
match NumberDecimalSeparator (which may be several characters) instead of '.'
match NegativeSign/PositiveSign instead of '-'
honour at least AllowLeadingWhite/AllowTrailingWhite, AllowLeadingSign, AllowDecimalPoint, AllowExponent and AllowThousands from style
If full NumberStyles support is out of scope, at minimum use the provider's separator and sign, so that Parse(x.ToString(p), p) round-trips. Add a round-trip test for de-DE.
Notes:ToString(culture) output cannot be parsed back with the same culture, which breaks the IParsable contract for every comma-decimal locale. The minimum fix is to use the provider's decimal separator and signs, so values round-trip. Full NumberStyles support can follow later.
Activity
matt-edmondson commentedon Sep 26, 2026
Triage
PreciseNumber.Parse(ReadOnlySpan<char>, NumberStyles, IFormatProvider?)and theIParsable/ISpanParsablesurfaceNotes:
ToString(culture)output cannot be parsed back with the same culture, which breaks theIParsablecontract for every comma-decimal locale. The minimum fix is to use the provider's decimal separator and signs, so values round-trip. FullNumberStylessupport can follow later.Generated by Claude Code