Value of floating in JSONValue

nrgyzer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 21 11:53:07 PDT 2014


Hi everyone,

I'm facing a problem with the JSON functions. I've to communicate
with another PC using JSON. Here's a simple snipped which shows
my problem:

import std.json;
import std.stdio;
void main()
{
	double d = 1.23456789;
	JSONValue j = d;
	sendToRemote(toJSON(&j));
}

My problem is that the remote PC receives 1.23457 instead of
1.23456789. But when I add the following:

import std.json;
import std.stdio;
void main()
{
	double d = 1.23456789;
	JSONValue j = d;
	sendToRemote(toJSON(&j));
	writefln("%.8f", j.floating);
}

writefln() shows me 1.23456789. So, the value is correct. I think
the problem is the default representation of any floating point
number to string. Is there any chance I can send 1.23456789
instead of 1.23457 to my remote PC?

Note: I cannot use strings because the other PC expects a numeric
data type.


More information about the Digitalmars-d-learn mailing list