Skip to content

Format specifies don't seem to be fully implemented #2582

Closed

Description

@zelenij

Description

Format specifies don't seem to be fully implemented. Specifically, thousands separator is not applied

Repro code

https://fable.io/repl/#?code=PYBwpgdgBAygngZwC5gLYFgBQpJQGICGARgDZgB0AwsAE5hY7SGkXV3kBSCAkhCjaCxYA2gB4AoqgCWSABQAiAO5SIAE2CLyBMjTkASAAwBKeUYB8AXSxkkUbWF1RZqMAgQEA5mABcUZDRUPI18AVwgZKABeKAArBAA5AiQpADd6TBsoADNaVCSnBF88XKSkYjIYJACIIKjYRBRUckrqj3Jimjy5BHaSpAAaP3IAcTAkAEEaDxCXPgRZIyMhDLGoVSksrLqARgM9rHtHWRzO-L15AG91ze94gFYAXzWCRDsPYFMsIA&html=Q&css=Q

Expected and actual results

Expected: 1,000
Actual: 1000

Related information

  • Fable version: dotnet fable --version
  • Operating system

Activity

  1. alfonsogarciacaro commented on Jan 7, 2022

    @alfonsogarciacaro
    Member

    Supporting all format specifiers is quite complicated and we're doing it bit by bit 😸 You can check which formats are supported in the String tests. In one of the latest releases we added support for thousand separators with the #,## pattern:

    testCase "String.Format works with thousands separator" <| fun () ->
    (12343235354.6547757).ToString() |> equal "12343235354.654776"
    (12343235354.6547757).ToString("#,##.000") |> equal "12,343,235,354.655"
    (12343235354.6547757M).ToString("#,##.000") |> equal "12,343,235,354.655"
    (123.456).ToString("#,##.00") |> equal "123.46"
    (123.456M).ToString("#,##.00") |> equal "123.46"
    (123438192123.456M).ToString("#,##.00") |> equal "123,438,192,123.46"
    (1.456M).ToString("#,##") |> equal "1"
    (1.456M).ToString("0,0") |> equal "01"

    If you need something in particular, could you please provide a test like the linked one with the expected results in .NET. Thank you very much!

  2. added a commit that references this issue on Mar 19, 2026
    885c730
  3. github-actions commented on Mar 19, 2026

    @github-actions
    Contributor

    🤖 This is an automated response from Repo Assist.

    Thanks for the report! I investigated the current status of the N format specifier and found that it has been partially fixed over time, but there's still a bug for the N0 case.

    Current status:

    • N / N2 (default precision 2): Works correctly — (1000).ToString("N2") → "1,000.00" ✓
    • N0 (zero decimal places): Broken — (1000).ToString("N0") → "1,000." (trailing dot instead of "1,000")

    Root cause in src/fable-library-ts/String.ts: the N format case unconditionally appends "." + decimal, even when precision = 0. The F format has the correct pattern (guards with if (precision > 0)), but N was missing this guard.

    I've submitted a fix in PR #4422 (if not yet visible, check the linked branch) that mirrors the F format's approach:

    if (precision > 0) {
      rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
    } else {
      rep = thousandSeparate(parts.integral);
    }

    Note: the same trailing-dot bug exists for P0 (percentage) and C0 (currency) format specifiers — those could be fixed in a follow-up PR if needed.

    Generated by Repo Assist · ◷

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f
    
  4. added a commit that references this issue on Mar 25, 2026
    995d251
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions