From f6e047e3423235a3825609db60612c7de53eddb4 Mon Sep 17 00:00:00 2001 From: Xie Han <63350856@qq.com> Date: Mon, 18 Dec 2023 02:19:18 +0800 Subject: [PATCH] Parse JSON number consistently. --- json_parser.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/json_parser.c b/json_parser.c index 30dd0f7..4b0e089 100644 --- a/json_parser.c +++ b/json_parser.c @@ -345,6 +345,23 @@ static double __evaluate_json_number(const char *integer, figures++; } + if (exp != 0 && figures != 0) + { + while (exp > 0 && figures < 18) + { + mant *= 10; + exp--; + figures++; + } + + while (exp < 0 && mant % 10 == 0) + { + mant /= 10; + exp++; + figures--; + } + } + num = mant; if (exp != 0 && figures != 0) {