[JS/TS] Fix C0 and P0 format specifiers producing trailing dot#4431
Merged
MangelMaxime merged 3 commits intomainfrom Mar 25, 2026
Merged
Conversation
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]>
11 tasks
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 the
C(currency) andP(percentage) format specifiers infable-library-ts/String.tsproducing a trailing dot when precision is 0.Before:
(1000).ToString("C0")→"¤1,000."(should be"¤1,000")(-1000).ToString("C0")→"(¤1,000.)"(should be"(¤1,000)")(0.5).ToString("P0")→"50. %"(should be"50 %")After:
(1000).ToString("C0")→"¤1,000"✓(-1000).ToString("C0")→"(¤1,000)"✓(0.5).ToString("P0")→"50 %"✓Root Cause
The
CandPformat cases inString.tsunconditionally built a string with a decimal separator, regardless of whether precision was 0. TheF(fixed-point) format already had the correct guard:if (precision > 0)before appending the decimal part. TheCandPcases were missing this guard.Fix
Mirror the
Fformat's guard in bothCandPcases:Note
The
Nformat specifier has the same issue and is addressed separately in PR #4422. This PR only touchesCandPto avoid conflicts.Test Plan
tests/Js/Main/StringTests.fsforC0,C2,P0,P2via bothToStringandString.Format