https://issues.dlang.org/show_bug.cgi?id=15885
Issue ID: 15885
Summary: float serialized to JSON loses precision
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: major
Priority: P1
Component: phobos
Assignee: [email protected]
Reporter: [email protected]
I've marked this issue as major because a lot of people are using JSON for
mobile app communication, and I discovered this because an incorrect invoice
was sent (fortunately only during testing).
In this code:
import std.json;
import std.stdio;
void main() {
JSONValue json;
json.type = JSON_TYPE.FLOAT;
json.floating = 30738.22;
writeln(toJSON(&json));
}
the resulting output is:
30738.2
The problem is that all float serialization just uses to!string() from
std.conv;
std.json should serialize to the standard @ json.org.
--