-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Double type converts to scientific notation #1661
Comments
I cannot reproduce the issue - the output is {"id":1431756631463478} on my machine. My guess would be that you're running a 32 bit system where the given number does not fit to an integer and is store as |
I run on 64-bit linux but get doubles converted to scientific. I know that rapidjson is using Grisu2 as well, but it does not convert to scientific. |
Do you have a working example? |
|
This is not about saving space. double d = 0.00004941;
std::cout << d << std::endl; The output is also It is about being able to round-trip values. The double std::printf("%A\n", d); The output is You get the same output after roundtripping: json j = json::parse("0.00004941");
std::printf("%a\n", j.get<double>()); There is currently no way to change this behavior. However, adding more decimal places does not make the output more precise. |
I agree. But what I am saying is not about |
Can you elaborate on the "human-friendly" aspect of these libraries? |
Assume you have a command-line tool that converts something to JSON format. You can grep (or use any other favourite text processing tool) stuff there. If your doubles are in a scientific notation it is hard to grep it. That was very simple one case, that is very popular where I am working. Another one can be the popular JSON web endpoints where one might desire investigating output. I quite sure you can find many more cases where human-readability of the raw format output is helpful. Just for the contrast, if you are an exchange and have REST endpoints, you probably, will choose the output to be as short as possible, rather then its readability. Does it make any sense? |
FYI, I personally don't find scientific notation any less readable, and often find it more readable for large/small numbers. |
@gregmarr Yeah, that is why I kind of think if there was a setting where you can control it, that would be nice for different use-cases. |
Sample:
nlohmann::json message;
message["id"] = 1431756631463478;
std::cout << message.dump();
Actual: { "id" : 1.431756631463478e+15 }
Expected: { "id" : 1431756631463478 }
Is there a setting for turning off scientific notation conversion?
The text was updated successfully, but these errors were encountered: