dimanche 4 décembre 2016

mongo-cxx-driver doubles to json

While experimenting with the C++11 driver of MongoDB (version 3.1.0-rc0) the output of the following piece of code confused me.

#include <iostream>

#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>

int main() {
  bsoncxx::builder::stream::document s;
  s << "x" << 1.0
    << "y" << 0.999999
    << "z" << 0.9999999;

  std::cout << bsoncxx::to_json(s) << std::endl;

  return 0;
}

Output:

{
    "x" : 1, 
    "y" : 0.999999, 
    "z" : 1
}

  1. Is this the expected behavior?
  2. How can I make sure that BSON doubles are represented as floating point numbers in JSON?
  3. How can I set the desired precision?

Aucun commentaire:

Enregistrer un commentaire