|
|
@ -505,17 +505,19 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out |
|
|
|
else |
|
|
|
{ |
|
|
|
if ( fabs(d - (int64_t)d) < 0.0000001 ) |
|
|
|
length = sprintf((char*)number_buffer, "%llu", (long long)d); |
|
|
|
length = sprintf((char *)number_buffer, "%llu", (long long)d); |
|
|
|
/* Try 8 decimal places of precision to avoid nonsignificant nonzero digits */ |
|
|
|
else length = sprintf((char*)number_buffer, "%0.8f", d); |
|
|
|
|
|
|
|
else length = sprintf((char *)number_buffer, "%0.8f", d); |
|
|
|
printf("d A -> (%s)\n",number_buffer); |
|
|
|
|
|
|
|
/* Check whether the original double can be recovered */ |
|
|
|
if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || ((double)test != d)) |
|
|
|
if ((sscanf((char *)number_buffer, "%lg", &test) != 1) || ((double)test != d)) |
|
|
|
{ |
|
|
|
if ( fabs(d - (int64_t)d) < 0.0000001 ) |
|
|
|
length = sprintf((char*)number_buffer, "%llu", (long long)d); |
|
|
|
length = sprintf((char *)number_buffer, "%llu", (long long)d); |
|
|
|
/* If not, print with 8 decimal places of precision */ |
|
|
|
else length = sprintf((char*)number_buffer, "%0.8f", d); |
|
|
|
else length = sprintf((char *)number_buffer, "%0.8f", d); |
|
|
|
printf("d B -> (%s)\n",number_buffer); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|