0

I have numbers much lower than zero (p.e. 1.34e-14) that I want to add to a json object. For this, I am using this code:

smallnumber=1.34e-14;
struct json_object *pointj=json_object_new_object();
json_object_object_add(pointj,"par", json_object_new_double(smallnumber);
cout << "\nThe json object created: " <<  json_object_to_json_string(pointj);

The problem is that the number appear truncated as 0.000000. Is it possible to specify the format of the output to have it in scientific notation?

user1046064
  • 3
  • 1
  • 4

1 Answers1

0

Probably there is more elegant solution to this issue but I solved it in this way:

double smallnumber=1.34e-14;
stringstream tmp;
tmp << smallnumber;
struct json_object *pointj=json_object_new_object();
json_object_object_add(pointj,"par", json_object_new_string(tmp.str().c_str());

It is working fine.

user1046064
  • 3
  • 1
  • 4