[CXX-1449] Conver doubles by from_json Created: 11/Oct/17  Updated: 11/Sep/19  Resolved: 08/Jan/18

Status: Closed
Project: C++ Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Evgeniy Assignee: Unassigned
Resolution: Incomplete Votes: 0
Labels: Bug
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

How i can convert json with floating point?

For exampl use src/bsoncxx/test/json.cpp, but

constexpr auto k_valid_json = R"({ "a" : 1, "b" : 2.2556 })";

in result i get

{ \"a\" : 1, \"b\" : 2.0 }

is expected

{ \"a\" : 1, \"b\" : 2.2556 }



 Comments   
Comment by Derick Rethans [ 26/Oct/17 ]

Hi!

I have just tried this out, with the following code:

#include <iostream>
 
#include <bsoncxx/json.hpp>
 
int main(int, char**) {
    constexpr auto k_valid_json = R"({ "a" : 1, "b" : 2.2556 })";
 
    const auto actual = bsoncxx::from_json(k_valid_json);
    const auto actual_view = actual.view();
 
    std::cout << bsoncxx::to_json(actual_view) << std::endl;
}

and compiled with:

$ g++ -std=c++11 -o cxx1449 cxx1449.cpp `pkg-config --cflags --libs libmongocxx`

When I run it, I get the following (expected) output:

$ ./cxx1449 
{ "a" : 1, "b" : 2.2555999999999998273 }

Can you let us know:

  • what your libmongoc version you use is?
  • what your libbson version you use it?
  • which mongocxx version are you are using?
  • what your locale is (echo $LANG)?
  • which platform you are on?
  • which compiler version you are using?
Comment by Evgeniy [ 11/Oct/17 ]

Hi,
for example i use this simple code

 
constexpr auto k_valid_json = R"({ "a" : 1, "b" : 2.2556 })";
 
const auto actual = bsoncxx::from_json(k_valid_json);
const auto actual_view = actual.view();
 
qDebug() << QString::fromStdString(bsoncxx::to_json(actual_view));

Comment by Derick Rethans [ 11/Oct/17 ]

Hi,

could you share some more code? For example, how you go from the

R"({ "a" : 1, "b" : 2.2556 })

to the result that you get. Did you insert, and then query the data, or something else?

cheers,
Derick

Generated at Wed Feb 07 22:02:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.