sprintf and printfn float formats %e, %g, and %f differ from .NET
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, typescript
- Domain
- backend
Research direction
Start by locating Fable's implementation of sprintf and printfn float formatting, then compare its %e, %g, and %f behavior with the .NET expectations and repro cases in the issue. Run the relevant formatting tests and add coverage for the listed edge cases, including precision zero and negative zero. Done when the outputs match the expected results and %.0g no longer throws.
Written by the indexing model from the issue text.
Description
Description
In Fable 5.27.0 targeting JavaScript/TypeScript, sprintf/printfn float format specifiers %e/%E, %g/%G, and %f diverge from .NET (String.Format in the same runtime already follows the .NET rules), and %.0g throws a RangeError (regression from 5.26.0).
Per the F# plaintext formatting reference, %e/%E defaults to precision 6 with a 3-digit exponent and matching case, %g/%G strips trailing zeros (treating precision 0 as default), %f never switches to exponential notation, and negative zero keeps its - sign.
Repro code
for s in [
sprintf "%e" 3.0
sprintf "%E" 3.0
sprintf "%.2g" 1e301
sprintf "%.8g" 0.0
sprintf "%.4e" -0.0
sprintf "%f" -0.0
sprintf "%.0f" 1e21
sprintf "%.0g" 2.5
] do
printfn "%s" s
Expected and actual results
Expected (.NET 10):
3.000000e+000
3.000000E+000
1e+301
0
-0.0000e+000
-0.000000
1000000000000000000000
2.5
Actual under Fable 5.27.0 (Node.js v24.14.1): the first seven lines print 3e+0, 3e+0, 1.0e+301, 0.0000000, 0.0000e+0, 0.000000, and 1e+21, and sprintf "%.0g" 2.5 throws RangeError: toPrecision() argument must be between 1 and 100.
Related information
- Fable version: 5.27.0
- Operating system: macOS 26.3 (Node.js v24.14.1, .NET 10)
Credit: https://ucsbplse.github.io/
- Dominant language
- F#
- Stars
- 3.2k
- Forks
- 335
- Avg merge
- 18h 57m
- Merged PRs (30d)
- 154
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from fable-compiler/Fable
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
fable-compiler/Fable#5280 ·
Maintainers usually reply within 1 day
-
agentic-workflows automation repo-assist
Difficulty 1/5 Under an hour Newbie friendliness 78/100
fable-compiler/Fable#4531 ·
Maintainers usually reply within 1 day
-
agentic-workflows automation repo-assist
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
fable-compiler/Fable#4522 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 57/100
fable-compiler/Fable#5279 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 5/5 Over a week Newbie friendliness 25/100
fable-compiler/Fable#5272 ·
Maintainers usually reply within 1 day
All issues in fable-compiler/Fable
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
binding:python bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
coollabsio/orbit#72 ·
Maintainers usually reply within 1 day
-
triage/confirmed
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
agentscope-ai/agentscope#3807 ·
Maintainers usually reply within 2 days
-
[Bug] Custom tool truncation leaves unused stream copies openPossibly taken @OUAO-FRANK claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day