cJSON icon indicating copy to clipboard operation
cJSON copied to clipboard

print: support float pretty print

Open dubw opened this issue 4 years ago • 2 comments

Code below:

float a = 0.00001; cJSON *root = cJSON_CreateObject(); cJSON_AddNumberToObject(root, "a", a); printf("%s\n", cJSON_Print(root));

Maybe it will print: { "a": 9.9999997473787516e-06 }

But that's not what we really want, we want this: { "a": 1e-5 }

Signed-off-by: dubaowei [email protected]

dubw avatar Dec 20 '21 11:12 dubw

This looks pretty similar to https://github.com/DaveGamble/cJSON/pull/558

Hallot avatar Feb 23 '22 10:02 Hallot

Yes, it's same in a way. But I only format the 'float' type, and it could be normal when object is 'integer' Besides that, I don't add any element to basic struct cJSON, keep it small but exquisite

dubw avatar Mar 14 '22 02:03 dubw