fix #41: Large numbers serialized incorrectly

pull/42/head
aleksanderd 2022-11-11 21:41:19 +03:00
parent dbf4b2dd2e
commit 15823a48b3
1 changed files with 6 additions and 1 deletions

View File

@ -108,7 +108,12 @@ local function encode_number(val)
if val ~= val or val <= -math.huge or val >= math.huge then
error("unexpected number value '" .. tostring(val) .. "'")
end
local intVal = math.tointeger(val)
if intVal == val then
return string.format("%d", intVal)
else
return string.format("%.14g", val)
end
end