Skip to content

Commit

Permalink
Changed encode_number() number->string conversion method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rxi committed Aug 15, 2015
1 parent 7b8aef0 commit 9beca8a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 9beca8a

Please sign in to comment.