Skip to content

core: make NumberUtils.formatDouble locale-independent (#150) - #174

Merged
jcgueriaud1 merged 1 commit into
masterfrom
claude/dramafinder-issue-150
Sep 7, 2026
Merged

jcgueriaud1 merged 1 commit into
masterfrom
claude/dramafinder-issue-150

Conversation

@jcgueriaud1

Copy link
Copy Markdown
Collaborator

Fixes #150.

Problem

NumberUtils.formatDouble built its formatter with new DecimalFormat("0.######"), whose no-symbols constructor picks up Locale.getDefault(Locale.Category.FORMAT). On a JVM running with e.g. -Duser.language=fr, formatDouble(0.5) returned "0,5" while the browser always reports "0.5" for a native input's value/step/min/max.

That broke every fractional assertion for consumers of the library, across all three affected elements:

  • ProgressBarElement — assertValue / assertMin / assertMax (aria-value*)
  • SliderElement — assertValue / assertMin / assertMax / assertStep
  • NumberFieldElement — assertStep / assertMin / assertMax

The repo's own suite never caught it: ApplicationServiceInitListener calls Locale.setDefault(Locale.UK) in the same JVM that runs the ITs.

Fix

Pass explicit ROOT symbols so the decimal separator is always .:

DecimalFormat df = new DecimalFormat("0.######",
        DecimalFormatSymbols.getInstance(Locale.ROOT));

Test

New NumberUtilsTest — the first plain unit test in the repo; surefire runs it via the JUnit engine already pulled in by spring-boot-starter-test. Five cases: whole values, fractional values, a Locale.FRANCE default, a FORMAT-category-only override (which Locale.setDefault(Locale) alone would miss), and no scientific notation for 0.000001. Each test restores both the default and the FORMAT-category locale in @AfterEach so nothing leaks into the IT JVM.

Verified the test actually pins the behaviour: with the fix reverted, the two locale cases fail with expected: <0.5> but was: <0,5>; with it in place all five pass.

🤖 Generated with Claude Code

DecimalFormat's no-symbols constructor uses the JVM default FORMAT
locale, so formatDouble(0.5) returned "0,5" on a JVM running with e.g.
-Duser.language=fr. The browser always reports "0.5" for a native
input's value/step/min/max, so every fractional assertion in
ProgressBarElement, SliderElement and NumberFieldElement failed for
consumers of the library. The repo's own suite never caught it because
ApplicationServiceInitListener sets Locale.UK in the IT JVM.

Pass DecimalFormatSymbols.getInstance(Locale.ROOT) so the decimal
separator is always ".", and add a unit test that covers both a
Locale.setDefault(Locale.FRANCE) default and a FORMAT-category-only
override.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jcgueriaud1
jcgueriaud1 merged commit 100b2af into master Sep 7, 2026
3 checks passed
@jcgueriaud1
jcgueriaud1 deleted the claude/dramafinder-issue-150 branch September 7, 2026 13:32
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.

NumberUtils.formatDouble uses the JVM default locale — fractional assertions fail on non-English JVMs

1 participant