[JS/TS] Fix N format specifier producing trailing dot when precision is 0#4422
Merged
MangelMaxime merged 1 commit intomainfrom Mar 25, 2026
Merged
Conversation
This was referenced Mar 19, 2026
github-actions bot
added a commit
that referenced
this pull request
Mar 21, 2026
When precision is 0, the C (currency) and P (percentage) format specifiers were appending a decimal separator with no decimal digits, producing results like "¤1,000." instead of "¤1,000", and "50. %" instead of "50 %". Mirror the guard already used by the F (fixed-point) format specifier: only append the decimal separator when precision > 0. The N format specifier has the same issue and is addressed separately in PR #4422. Co-Authored-By: Repo Assist <[email protected]>
When using ToString("N0") or String.Format("{0:N0}", ...), the N format
specifier was producing a trailing dot (e.g. "1,000." instead of "1,000").
The bug was in String.ts where the decimal separator was always appended
regardless of precision, unlike the F format which guards with precision > 0.
Adds tests for N0, N2, and N (default) format specifiers. Fixes #2582.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
885c730 to
995d251
Compare
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.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Fixes #2582 —
ToString("N0")andString.Format("{0:N0}", ...)produce"1,000."(with a trailing dot) instead of"1,000".Root Cause
In
src/fable-library-ts/String.ts, theNformat case always appended a decimal separator and decimal digits:When
precision = 0,toFixed(1000, 0)gives"1000",splitIntAndDecimalPartgives{integral: "1000", decimal: ""}, and the code produced"1,000."(thousands separator applied correctly but trailing dot incorrectly added).The
Fformat case already has the correct pattern — it guards withif (precision > 0)before adding the decimal part. TheNformat case lacked this guard.Fix
Mirror the
Fformat's guard:Test Plan
Added tests for N0, N2, and N (default) format specifiers via both
ToStringandString.Format:(1000).ToString("N0")→"1,000"✓(12345678).ToString("N0")→"12,345,678"✓(-1000).ToString("N0")→"-1,000"✓(1000).ToString("N2")→"1,000.00"✓(1000).ToString("N")→"1,000.00"✓Note: The
P(percentage) andC(currency) format cases have the same trailing-dot issue forP0/C0. Those are lower-priority since their defaults are non-zero precision, but they could be fixed in a follow-up.🤖 Generated with Repo Assist