c - How to specify number of digits to output for real numbers in Jansson -


how can specify fixed number of digits output after decimal point when using jansson's json_dumps or json_dumpf() output real numbers?

i tried jansson's new json_real_precision flag, specifies maximum number of significant digits, not fixed number of digits after decimal point.

basically i'm looking in jansson behaves following call printf in c (with expected output of 123.12346):

printf("%.5f", 123.123456789); 

[edit]

here's sample code illustrate output styles i've tried far (requires jansson 2.7+):

#include <stdio.h> #include <jansson.h>  int main(int argc, char* argv[]) {   json_t *json = json_object();    json_object_set_new(json, "foo", json_real(123.123456789));   printf("output of json_dumps() 123.123456789: %s\n", json_dumps(json, 0));   printf("again, using json_real_precision(5) : %s\n", json_dumps(json, json_real_precision(5)));    return 0; } 

output:

output of json_dumps() 123.123456789: {"foo": 123.123456789} again, using json_real_precision(5) : {"foo": 123.12} 

again, need way output fixed number of digits after decimal (e.g. 123.12346), know how achieve this?.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -