-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
types: ensure double serializatiion with decimal places
The `%g` printf format used for serializing double values into strings will not include any decimal place if the value happens to be integral, leading to an unwanted double to integer conversion when serializing and subsequently deserializing an integral double value as JSON. Solve this issue by checking the serialized string result for a decimal point or exponential notation and appending `.0` if neither is found. Ref: #173 Suggested-by: Felix Fietkau <[email protected]> Signed-off-by: Jo-Philipp Wich <[email protected]>
- Loading branch information
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
When formatting integral double values as JSON, ensure that at least one | ||
decimal place is retained. | ||
|
||
-- Testcase -- | ||
printf("%.J\n", [ | ||
1e100, | ||
1.23, | ||
4.00, | ||
1.0/3*3, | ||
]); | ||
-- End -- | ||
|
||
-- Args -- | ||
-R | ||
-- End -- | ||
|
||
-- Expect stdout -- | ||
[ | ||
1e+100, | ||
1.23, | ||
4.0, | ||
1.0 | ||
] | ||
-- End -- |
This file contains 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