How to control the serialization format in the boost json library. I am trying to serialize this object and the floats are being output in scientific notation. How to output in fixed notation like 12000000 instead of 1.2E7? And 0 instead of 0E0.
i.e.
{"id":"de69041b-141b-4e01-b349-458f26f08259","price":3.343403E12,"qty":1.2E7}
{"id":"de69041b-141b-4e01-b349-458f26f08259","price":0E0,"qty":0E0}
Here is a minimal program that will output floats in exponential format (ubuntu 20.04, g++ 9.3.0, boost 1.76.0)
#include <iostream>
#include <boost/json/src.hpp>
using namespace std;
namespace bj = boost::json;
int main(void)
{
bj::object obj1 = {
{"id", 1},
{"price", 3343403000000.00},
{"qty", 13546000000000.00}
};
bj::object obj2 = {
{"id", 2},
{"price", 0.0},
{"qty", 0.0}
};
cout << "obj1:" << bj::serialize(obj1) << endl;
cout << "obj2:" << bj::serialize(obj2) << endl;
return 0;
}
Output:
obj1:{"id":1,"price":3.343403E12,"qty":1.3546E13}
obj2:{"id":2,"price":0E0,"qty":0E0}