[Issue 15885] New: float serialized to JSON loses precision
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Apr 6 05:29:56 PDT 2016
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: nobody at puremagic.com
Reporter: rjmcguire at gmail.com
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.
--
More information about the Digitalmars-d-bugs
mailing list