Conversation
JsonValue.Float(100.0).ToString() previously returned "100" instead of
"100.0", discarding the fact that the value is a float. This causes issues
when downstream consumers expect a JSON float (not an integer).
Root cause: the write path used w.Write(number) for the Float DU case which
calls number.ToString() — and (100.0).ToString() returns "100" in .NET.
Fix: format the float using the "R" round-trip format and, if the result
contains no decimal point or exponent character, append ".0". This matches
the behaviour of JsonValue.Parse("100.0") which correctly serialises as
"100.0" (because decimal 100M with Scale=1 already has the trailing zero).
Closes #1356
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4 tasks
dsyme
approved these changes
Feb 22, 2026
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.
🤖 Repo Assist here — I'm an automated AI assistant for this repository.
Closes #1356
Problem
JsonValue.Float(100.0).ToString()returns"100"instead of"100.0", discarding the fact that the value is a float. This violates downstream contracts that expect a JSON float.Root Cause
JsonValue.WriteTopreviously wroteFloatvalues usingw.Write(number), which calls(100.0 : float).ToString(). In .NET,(100.0).ToString()returns"100"— no decimal point — because IEEE 754 doubles carry no information about trailing zeros.By contrast,
JsonValue.Parse("100.0")stores the value asJsonValue.Number(Decimal.Parse("100.0")), anddecimalpreserves scale (trailing zeros), so it serialises as"100.0"correctly.Fix
For the
Floatcase, format using the"R"(round-trip) format specifier withInvariantCulture, then append".0"if the result contains no decimal point and no exponent character — making the output unambiguously look like a JSON float:Examples after the fix:
JsonValue.Float(100.0)"100""100.0"✓JsonValue.Float(100.5)"100.5""100.5"(unchanged) ✓JsonValue.Float(1e20)"1E+20""1E+20"(unchanged) ✓JsonValue.Float(nan)"null""null"(unchanged) ✓Test
Added three regression tests to
JsonValue.fscovering the fixed case, fractional floats, and scientific notation.Test Status
dotnet build src/FSharp.Data.Json.Core/)FSharp.Data.Core.Testspass (2840 passed + 1 pre-existing failure: network test hittingwww.google.com, blocked by build environment firewall — unrelated to this change)Warning
The following domain was blocked by the firewall during workflow execution:
www.google.com