Skip to content

Commit 15823a4

Browse files
committed
fix rxi#41: Large numbers serialized incorrectly
1 parent dbf4b2d commit 15823a4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

json.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ local function encode_number(val)
108108
if val ~= val or val <= -math.huge or val >= math.huge then
109109
error("unexpected number value '" .. tostring(val) .. "'")
110110
end
111-
return string.format("%.14g", val)
111+
local intVal = math.tointeger(val)
112+
if intVal == val then
113+
return string.format("%d", intVal)
114+
else
115+
return string.format("%.14g", val)
116+
end
112117
end
113118

114119

0 commit comments

Comments
 (0)