openresty / lua-cjson

Lua CJSON is a fast JSON encoding/parsing module for Lua
http://www.kyne.com.au/~mark/software/lua-cjson.php
MIT License
434 stars 119 forks source link

Does not retain the decimal places as .0 float #100

Open zzyy3321 opened 8 months ago

zzyy3321 commented 8 months ago

Issue Description: When using the lua cjson library to encode Lua tables containing floating-point numbers with decimal places, the output JSON does not retain the decimal places as expected.

Steps to Reproduce:

local table = {}
table["a"] = 80.00
local j = require "cjson.safe"
local json = j.encode(table)
ngx.say(json)

Expected Output: The expected JSON output should retain the decimal places for floating-point numbers, for example:

{
    "a": 80.00
}

Actual Output: The actual JSON output does not retain the decimal places, for example:

{
    "a": 80
}

I have tested this issue using the lua cjson library on openresty and confirmed the behavior described above.

zhuizhuhaomeng commented 8 months ago

This doesn't appear to be a problem, as there is no loss of accuracy.