Skip to content

Commit

Permalink
chore(json): update json to use 20 sig digits
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Oct 23, 2024
1 parent 9f651e8 commit 0fe6085
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,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
if math.floor(val) == val then
-- Large integers: avoid scientific notation and print as an integer
return string.format("%.0f", 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
-- Decimals: use the 'g' format to print floating point with precision, up to 14 significant digits
return string.format("%.14g", val)
-- Use 20 significant digits for non-integer numbers
return string.format("%.20g", val)
end
end

Expand Down

0 comments on commit 0fe6085

Please sign in to comment.