Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(json): modify json.lua to support larger numbers #1053

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion dev-cli/container/src/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,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
return string.format("%.14g", val)
if math.floor(val) == val then
-- Large integers: avoid scientific notation and print as an integer
return string.format("%.0f", val)
else
-- Decimals: use the 'g' format to print floating point with precision, up to 14 significant digits
return string.format("%.14g", val)
Copy link
Member

@TillaTheHun0 TillaTheHun0 Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should be .20g based on this comment. ao uses a compilation of Lua 5.3 which introduced the 64 bit integers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep that would work. will make the change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified - 2c8aa83

end
end

local type_func_map = {
Expand Down