mirror of https://github.com/DaveGamble/cJSON
Compare commits
2 Commits
507366bdba
...
be60d05ede
Author | SHA1 | Date |
---|---|---|
slark-yuxj | be60d05ede | |
“uinontech_yuxiaojun” | b64963332f |
23
cJSON.c
23
cJSON.c
|
@ -568,15 +568,22 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out
|
|||
}
|
||||
else
|
||||
{
|
||||
/* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */
|
||||
length = sprintf((char*)number_buffer, "%1.15g", d);
|
||||
if(item->valuedouble == item->valueint)
|
||||
{
|
||||
length = sprintf((char*)number_buffer, "%d", item->valueint);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */
|
||||
length = sprintf((char*)number_buffer, "%1.15g", d);
|
||||
|
||||
/* Check whether the original double can be recovered */
|
||||
if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || !compare_double((double)test, d))
|
||||
{
|
||||
/* If not, print with 17 decimal places of precision */
|
||||
length = sprintf((char*)number_buffer, "%1.17g", d);
|
||||
}
|
||||
/* Check whether the original double can be recovered */
|
||||
if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || !compare_double((double)test, d))
|
||||
{
|
||||
/* If not, print with 17 decimal places of precision */
|
||||
length = sprintf((char*)number_buffer, "%1.17g", d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* sprintf failed or buffer overrun occurred */
|
||||
|
|
Loading…
Reference in New Issue