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,8 +108,13 @@ local function encode_number(val)
|
|||
if val ~= val or val <= -math.huge or val >= math.huge then
|
||||
error("unexpected number value '" .. tostring(val) .. "'")
|
||||
end
|
||||
local intVal = math.tointeger(val)
|
||||
if intVal == val then
|
||||
return string.format("%d", intVal)
|
||||
else
|
||||
return string.format("%.14g", val)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local type_func_map = {
|
||||
|
|
Loading…
Reference in New Issue