Skip to content

[JS/TS] Fix C0 and P0 format specifiers producing trailing dot#4431

Merged
MangelMaxime merged 3 commits intomainfrom
repo-assist/fix-pc-format-specifier-trailing-dot-f93ebed8069fcabc
Mar 25, 2026
Merged

[JS/TS] Fix C0 and P0 format specifiers producing trailing dot#4431
MangelMaxime merged 3 commits intomainfrom
repo-assist/fix-pc-format-specifier-trailing-dot-f93ebed8069fcabc

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Fixes the C (currency) and P (percentage) format specifiers in fable-library-ts/String.ts producing 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 C and P format cases in String.ts unconditionally built a string with a decimal separator, regardless of whether precision was 0. The F (fixed-point) format already had the correct guard: if (precision > 0) before appending the decimal part. The C and P cases were missing this guard.

Fix

Mirror the F format's guard in both C and P cases:

// C format
if (precision > 0) {
  rep = "¤" + thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
} else {
  rep = "¤" + thousandSeparate(parts.integral);
}
// P format
if (precision > 0) {
  rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0") + " %";
} else {
  rep = thousandSeparate(parts.integral) + " %";
}

Note

The N format specifier has the same issue and is addressed separately in PR #4422. This PR only touches C and P to avoid conflicts.

Test Plan

  • Added tests in tests/Js/Main/StringTests.fs for C0, C2, P0, P2 via both ToString and String.Format
  • CI JavaScript test suite validates output

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f

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 <noreply@github.com>
@github-actions github-actions bot added automation Automated changes repo-assist Created by Repo Assist labels Mar 21, 2026
@MangelMaxime MangelMaxime marked this pull request as ready for review March 25, 2026 21:14
@MangelMaxime MangelMaxime changed the title [Repo Assist] [JS/TS] Fix C0 and P0 format specifiers producing trailing dot [JS/TS] Fix C0 and P0 format specifiers producing trailing dot Mar 25, 2026
@MangelMaxime MangelMaxime merged commit e3dda97 into main Mar 25, 2026
23 checks passed
@MangelMaxime MangelMaxime deleted the repo-assist/fix-pc-format-specifier-trailing-dot-f93ebed8069fcabc branch March 25, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation Automated changes repo-assist Created by Repo Assist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant