Skip to content
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

float precision #1384

Closed
vassilisw opened this issue Dec 6, 2018 · 1 comment
Closed

float precision #1384

vassilisw opened this issue Dec 6, 2018 · 1 comment

Comments

@vassilisw
Copy link

When a float is dumped and becomes float again via json::parse, looses precision

    json jjj;
    jjj["f"] = 11.123456789;
    float f = json::parse(jjj.dump())["f"];
    std::cout << f << std::endl;

expected: 11.12345678..
getting: 11.1235

Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin16.7.0

Is there any way to increase precision?

@gregmarr
Copy link
Contributor

gregmarr commented Dec 6, 2018

Yes, increase your output precision:

std::cout.precision(12);
std::cout << f << std::endl;

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

No branches or pull requests

2 participants