From 9beca8a5bd683f12f0659ca067b5810f9ade6329 Mon Sep 17 00:00:00 2001 From: rxi Date: Sat, 15 Aug 2015 11:42:38 +0100 Subject: [PATCH] Changed encode_number() number->string conversion method Using Lua5.3, tonumber() will represent the float `1` as "1.0" instead of "1". Using string.format("%14g, x) `1` is converted to "1" regardless of whether it's an int or float. All other conversions seem to be uneffected. --- json.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json.lua b/json.lua index 40b75c8..4115a53 100644 --- a/json.lua +++ b/json.lua @@ -83,7 +83,7 @@ local function encode_number(val) if val ~= val or val <= -math.huge or val >= math.huge then error("unexpected number value '" .. tostring(val) .. "'") end - return tostring(val) + return string.format("%.14g", val) end