Fable
Fable copied to clipboard
Double-to-string format using "G17" does not match .NET
Description
Using the "G17" float format doesn't match .NET.
Repro code
let f (x: float) = printfn "%s" (x.ToString("G17"))
f 123.45
f 10_000.0
f 0.000222
Expected and actual results
.NET output:
123.45
10000
0.000222
Fable output:
123.45000000000000
10000.000000000000
0.00022200000000000000
It seems that .NET is just omitting the trailing zeros? Here are the docs, for reference: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#GFormatString
As a workaround, I'm just using ToString without a format specifier and it seems to be working for my purposes for now. I was just needing a float format that could round-trip, and MS docs recommend you use "G17", but I don't seem to be having any issues with whatever the default is yet.
Related information
- Fable version: 3.6.3
- .NET version: 6.0.100
- Operating system: Windows 10.0.19043