Repository navigation
Read the number separators as well as the currency ones under AllowCurrencySymbol [patch] - #198
Merged
Merged
Conversation
…rrencySymbol [patch]
Parse used the currency separators only once a symbol had been stripped, and
the number separators otherwise. The BCL reads the currency separators first
whenever the style allows a symbol, and the number separators too unless a
symbol came ahead of the digits. For a culture that writes money with other
separators than its numbers (en-DE, fr-CH, de-AT), Parse("1.25", en-DE)
returned 125 and Parse("1.5", fr-CH) threw, where decimal reads 1.25 and 1.5.
Fixes #195
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW3RtuaocwQ2QRF7djh
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



ParseusedCurrencyDecimalSeparatorandCurrencyGroupSeparatoronly after it had stripped a currency symbol. Otherwise it used the number separators.The BCL does this differently whenever the style includes
AllowCurrencySymbol, whichNumberStyles.Anydoes, andAnyis what the defaultParse(s, provider)uses:Some cultures write money with different separators from other numbers, such as en-DE, fr-CH and de-AT. There, PreciseNumber disagreed with
decimal:Parse("1.25", en-DE)returned 125;Parse("1.5", fr-CH)threw.Change
ChooseSeparatorspicks a primary pair and a fallback pair. The primary pair is the currency separators when the style allows a symbol, and the number separators otherwise. The fallback pair is the number separators, used only when the style allows a symbol and none was read ahead of the digits.MatchSeparatortries the primary separator, then the fallback. The decimal separator is still tried before the group separator, and a group separator may still only follow integral digits.StripAffixesnow reports whether the symbol was leading. A trailing symbol is read after the digits in the BCL too.Tests
TestParseAcceptsWhatDecimalAcceptsgains two hand-built formats whose currency and number separators differ:Mixed, shaped like en-DE;Swiss, shaped like fr-CH."1.5","1.25","1 234.5","1,5 €","1 234,50 CHF","CHF 1 234.50"and"€1,5"underAnyandCurrency.TestParseRejectsWhatDecimalRejectsgains"CHF 1,5": after a leading symbol, only the currency separators are read.TestDefaultParseReadsCurrencySeparatorsAsDecimalDoescovers theParse(s, provider)andTryParse(s, provider, out)overloads. It uses hand-built formats, so it does not depend on ICU and runs in globalization-invariant mode.One existing test fixture changed.
PreciseNumberParseCultureTests.CommaDecimalis "shaped like de-DE", but it left the currency separators at the invariant.and,. UnderAny,decimal.TryParse("1.234.567,5", NumberStyles.Any, CommaDecimal)returns false, soParse_HonoursLeadingSignWhitespaceAndThousandsUnderNumberStylesAnywas pinning behaviour the BCL doesn't have. The fixture now sets the currency separators de-DE actually uses (,and.), and the test still checks thousands grouping underAny.The full suite passes: 604 tests. I did not run benchmarks: the change adds at most one extra separator comparison per character, and only under currency styles.
Note: #194 also edits
Parse's digit loop, so whichever lands second may need a small rebase.Fixes #195
Generated by Claude Code