Skip to content

(Double)Real value write as Integer #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dcracker opened this issue Nov 19, 2014 · 7 comments
Closed

(Double)Real value write as Integer #85

dcracker opened this issue Nov 19, 2014 · 7 comments
Labels

Comments

@dcracker
Copy link

Value json;
json["dbl"] = 0.0;
// json["dbl"].type() == realValue

FastWriter writer;
string str = writer.write( json );
// "dbl" becomes 0

Reader reader;
reader.read( str, json );
// json["dbl"].type() == intValue

writer's sprintf with %g doesn't print dot when 0 below.
%lf is OK. but not optimized.
Maybe need to add some codes.
Or am I misunderstand something?

@jacobsa
Copy link
Contributor

jacobsa commented Nov 20, 2014

I think this is acceptable behavior. JSON doesn't distinguish various sorts of
numbers, so "0" is a reasonable way to represent the double value zero. Ditto
on input: the integer zero is a reasonable way to parse "0". You shouldn't rely
on typing of numbers to round-trip; rather only values.

@dcracker
Copy link
Author

OK, now I understand.... maybe?
JSON does not care Integer or Real. They are just part of Number.
And JSON care the Number type. right?
I referenced this site : http://www.json.org

@ondratu
Copy link

ondratu commented Mar 13, 2018

Hi,
in my opinion that is bad solution.

If is possible to write same output as is read, it could be write. So when you have some clever mechanism to identify number as int, resp. real, you could write real. This do python for example.

I know, that i can retype values to real from int, but for generic reading, type changing is problem.

@cdunn2001
Copy link
Contributor

@ondratu, I don't think this happens for the StreamWriter, does it?

@ondratu
Copy link

ondratu commented Mar 15, 2018

Yes, here is output from my sample code (build on debian buster with libjsoncpp version 1.7.4):

original:	{"int":78866000000,"real":78866000000.0}
	int type: 2, real type: 3
writed: 	{"int":78866000000,"real":78866000000}
	int type: 2, real type: 2

json.cc

@cdunn2001
Copy link
Contributor

Hmmm. I could be wrong, but I think the most recent commit to master actually appends a . always. Could you try that?

@ondratu
Copy link

ondratu commented May 10, 2018

Yes, master works. Thanks a lot ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants