mirror of https://github.com/rxi/json.lua.git
fix #41: Large numbers serialized incorrectly
parent
dbf4b2dd2e
commit
15823a48b3
5
json.lua
5
json.lua
|
@ -108,7 +108,12 @@ local function encode_number(val)
|
||||||
if val ~= val or val <= -math.huge or val >= math.huge then
|
if val ~= val or val <= -math.huge or val >= math.huge then
|
||||||
error("unexpected number value '" .. tostring(val) .. "'")
|
error("unexpected number value '" .. tostring(val) .. "'")
|
||||||
end
|
end
|
||||||
|
local intVal = math.tointeger(val)
|
||||||
|
if intVal == val then
|
||||||
|
return string.format("%d", intVal)
|
||||||
|
else
|
||||||
return string.format("%.14g", val)
|
return string.format("%.14g", val)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue