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

Floating point value loses decimal point during dump #818

Closed
kishorenc opened this issue Nov 5, 2017 · 1 comment
Closed

Floating point value loses decimal point during dump #818

kishorenc opened this issue Nov 5, 2017 · 1 comment

Comments

@kishorenc
Copy link

kishorenc commented Nov 5, 2017

Bug Report

Let's say I've a floating point value "4.0". When it's dumped to disk using .dump() it's being written as just "4". So, the type of the value goes from float to int when I read the data back using parse().

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?
std::string json_str = "{\"average_rating\": 4.0 }";
nlohmann::json document = nlohmann::json::parse(json_str);
std::cout << "Float? " << document["average_rating"].is_number_float() << std::endl;
std::string json_serialized = document.dump();
std::cout << "json_serialized: " << json_serialized << std::endl;
document = nlohmann::json::parse(json_serialized);
std::cout << "Float? " << document["average_rating"].is_number_float() << std::endl;

The output:

Float? 1
json_serialized: {"average_rating":4}
Float? 0
  • What is the expected behavior?

The .dump() should not drop the trailing ".0".

  • And what is the actual behavior instead?

The .dump() drops the trailing .0.

Apple LLVM version 7.3.0 (clang-703.0.31)

  • Did you use a released version of the library or the version from the develop branch?

Release version.

@kishorenc
Copy link
Author

Sorry, this has been fixed in a later release via: #378

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

1 participant