Render the number nicely from the given item into a string. */
| 136 | |
| 137 | /* Render the number nicely from the given item into a string. */ |
| 138 | static char *print_double(cJSON *item) { |
| 139 | char *str; |
| 140 | double d = item->valuedouble; |
| 141 | str = reinterpret_cast<char *>(cJSON_malloc(64)); /* This is a nice tradeoff. */ |
| 142 | if (str) { |
| 143 | if (fabs(floor(d) - d) <= DBL_EPSILON) { |
| 144 | sprintf(str, "%.0f", d); |
| 145 | } else if (fabs(d) < 1.0e-6 || fabs(d) > 1.0e9) { |
| 146 | sprintf(str, "%lf", d); |
| 147 | } else { |
| 148 | sprintf(str, "%f", d); |
| 149 | } |
| 150 | } |
| 151 | return str; |
| 152 | } |
| 153 | |
| 154 | static char *print_int(cJSON *item) { |
| 155 | char *str; |