Skip to content

Keep floating-point magic descriptions independent of the default locale - #94

Open
PHJ2000 wants to merge 1 commit into
j256:mainfrom
PHJ2000:fix-locale-independent-numeric-formatting
Open

PHJ2000 wants to merge 1 commit into
j256:mainfrom
PHJ2000:fix-locale-independent-numeric-formatting

Conversation

@PHJ2000

@PHJ2000 PHJ2000 commented Oct 22, 2026

Copy link
Copy Markdown

Fixes #41.

Floating-point magic descriptions currently use the JVM's default numeric locale. For example, %f formats 1.25 as 1,25 under Spanish or German and as ١٫٢٥ under Arabic. This also makes the existing formatter and file-recognition tests depend on the host locale.

Use Locale.ROOT decimal symbols for both decimal and scientific formats, keeping the decimal separator, digits, and exponent notation consistent. Regression tests cover Spanish, German, and Arabic with %f, %e, %g and their uppercase variants, including default, zero, and explicit precision. Each test restores the previous format locale in a finally block.

Validation:

  • Before the production change, all three new locale regression tests fail.
  • JDK 11: mvn -B -ntp clean package passed (364 tests, 2 skipped, no failures or errors).
  • JDK 11: mvn -B -ntp -Duser.language=es -Duser.country=ES test passed with the same totals.
  • git diff --check: passed.

Use root-locale decimal symbols for decimal and scientific formats. Cover Spanish, German, and Arabic numeric locales with the supported floating-point conversions and precision settings.

Fixes j256#41.

Signed-off-by: Jaehong Park <105151063+PHJ2000@users.noreply.github.com>
@j256

j256 commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Thanks for this @PHJ2000. What is the ramifications of forcing this locale on people that are running in those countries? Are the decimal output not going to match their expected restuls? Shouldn't just the tests set the locale to ROOT?

@PHJ2000

PHJ2000 commented Oct 26, 2026

Copy link
Copy Markdown
Author

You're right: the current patch changes user-visible output, not just the tests. For example, a Spanish or German decimal description changes from 1,25 to 1.25, and Arabic-format digits/separators change to the ROOT representation. Users expecting localized descriptions would observe that change.

I chose ROOT on the assumption that magic descriptions should be stable across machines, but #41 reports locale-dependent test failures; it does not by itself establish that production output should be locale-independent. That assumption needs to be made explicit.

Setting a known FORMAT locale in the affected formatter and file-recognition tests, then restoring it after each test, is the narrower fix for #41. It would preserve the existing locale-sensitive behavior for callers. I propose revising this PR to that test-only scope unless locale-independent descriptions are the intended library contract. Does that match your preference?

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.

System language dependant test failure

2 participants