fix #41: Large numbers serialized incorrectly #9

pull/44/head
alexandro-rezakhani 2022-11-20 01:10:24 -05:00 committed by GitHub
parent 22e38a11d4
commit 6006d0fcc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -123,7 +123,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
return tostring(val)
local intVal = math.tointeger(val)
if intVal == val then
return string.format("%d", intVal)
else
return string.format("%.14g", val)
end
end