Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
return string.format("%.14g", val)
-- Handle integer values separately to avoid floating-point conversion
if math.type(val) == "integer" then
return string.format("%d", val) -- Format as an integer
else
-- Use 20 significant digits for non-integer numbers
return string.format("%.20g", val)
end


Expand Down