From 501ff3b3d0e977b964e8c0ae43c519daebdee707 Mon Sep 17 00:00:00 2001 From: Dave Gamble Date: Wed, 25 Nov 2009 15:18:19 +0000 Subject: [PATCH] if it's a big number, but still an integer, print it exactly! git-svn-id: http://svn.code.sf.net/p/cjson/code@18 e3330c51-1366-4df0-8b21-3ccf24e3d50e --- cJSON.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cJSON.c b/cJSON.c index 2ba22fd..a429ee7 100644 --- a/cJSON.c +++ b/cJSON.c @@ -121,8 +121,9 @@ static char *print_number(cJSON *item) else { str=(char*)cJSON_malloc(64); // This is a nice tradeoff. - if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d); - else sprintf(str,"%f",d); + if (fabs(floor(d)-d)<=DBL_EPSILON) sprintf(str,"%.0f",d); + else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d); + else sprintf(str,"%f",d); } return str; } -- GitLab