我的数字远小于零(p.e.1.34e-14),我想添加到一个json对象中。为此,我使用以下代码:
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);问题是这个数字似乎被截断为0.000000。是否可以指定输出的格式,使其采用科学记数法?
发布于 2013-10-20 16:01:55
也许这个问题有更好的解决方案,但我是这样解决的:
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());它工作得很好。
https://stackoverflow.com/questions/19470726
复制相似问题