Skip to content

[Runtime] Create usCulture without user overrides - #2100

Merged
RobertvanderHulst merged 1 commit into
X-Sharp:devfrom
hpetriffer:fix/usculture-no-user-override
Oct 14, 2026
Merged

RobertvanderHulst merged 1 commit into
X-Sharp:devfrom
hpetriffer:fix/usculture-no-user-override

Conversation

@hpetriffer

Copy link
Copy Markdown
Contributor

Problem

ConversionHelpers.usCulture (XSharp.Core Convert.prg, XSharp.RT Conversions.prg) is meant to be a fixed reference culture, but it is created with CultureInfo{"en-US"}, which applies the user's overrides. When the Windows format is "English (United States)" with the decimal symbol changed to , and digit grouping to ., _VOVal / _Val parse with NumberStyles.Number and treat . as a group separator. Nothing raises an error; the numbers are just wrong. FormatNumber (Str/NTrim/Transform) has the same problem and outputs , regardless of SetDecimalSep().

Repro (on such a machine)

Val("0.9999999999") → 9999999999. In plain .NET:

[double]::Parse("0.9999999999", [Globalization.NumberStyles]::Number, [Globalization.CultureInfo]::new("en-US"))   # 9999999999

Fix

CultureInfo{"en-US", false} in both assemblies. Unaffected users see no change; InvariantCulture was deliberately not used.

Tests

New UsCulture collection (parallelization disabled) in XSharp.Core.Tests and XSharp.RT.Tests:

  • One test asserts UseUserOverride == false and the . / , separators.
  • A behaviour test swaps in an en-US clone with swapped separators, shows Val("0.99") → 99 and Str(1.5,4,1) → " 1,5", then restores the original culture and checks the correct results.

The invariant tests fail without the fix and pass with it. The rest of the Core/RT suites shows the same order-dependent failures with and without this change (shared global state such as Dialect/SetDecimalSep across parallel test classes).

🤖 Generated with Claude Code

ConversionHelpers.usCulture (XSharp.Core and XSharp.RT) was created with
CultureInfo{"en-US"}, which applies the Windows user overrides. When the
user format is "English (United States)" with decimal symbol "," and digit
grouping ".", Val("0.9999999999") returned 9999999999, because
NumberStyles.Number treats "." as a group separator. Str()/Transform()
emitted "," and ignored SetDecimalSep().

Use CultureInfo{"en-US", false} so the reference culture always uses
"." / ",". Add tests for the invariant and a test that reproduces the
bug by swapping usCulture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@RobertvanderHulst

Copy link
Copy Markdown
Member

Hansjoerg and Claude, good catch!

@RobertvanderHulst
RobertvanderHulst merged commit c254160 into X-Sharp:dev Oct 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants