diff options
author | Brandon <lordnynex@gmail.com> | 2015-11-01 01:51:30 -0700 |
---|---|---|
committer | Yichun Zhang (agentzh) <agentzh@gmail.com> | 2015-11-04 22:37:29 +0800 |
commit | f79aa68af865ae84b36c7e794beedd87fef2ed54 (patch) | |
tree | 882359f4bca0651aff399cb18c1779e65a3cc7a1 /tests/agentzh.t | |
parent | fab1440c3268fa415d098ff37bf0f929eeb53844 (diff) | |
download | lua-cjson-2.1.0.3.tar.gz lua-cjson-2.1.0.3.tar.bz2 lua-cjson-2.1.0.3.zip |
feature: now we allow up to 16 decimal places in JSON number encoding via cjson.encode_number_precision().2.1.0.3
thanks lordnynex for the patch in #4.
Test cases for changing precision
Diffstat (limited to '')
-rw-r--r-- | tests/agentzh.t | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/agentzh.t b/tests/agentzh.t index e65288f..0b546ff 100644 --- a/tests/agentzh.t +++ b/tests/agentzh.t | |||
@@ -50,3 +50,18 @@ print(cjson.encode(b)) | |||
50 | --- out | 50 | --- out |
51 | ["a=1&b=2"] | 51 | ["a=1&b=2"] |
52 | 52 | ||
53 | |||
54 | |||
55 | === TEST 5: default and max precision | ||
56 | --- lua | ||
57 | local math = require "math" | ||
58 | local cjson = require "cjson" | ||
59 | local double = math.pow(2, 53) | ||
60 | print(cjson.encode(double)) | ||
61 | cjson.encode_number_precision(16) | ||
62 | print(cjson.encode(double)) | ||
63 | print(string.format("%16.0f", cjson.decode("9007199254740992"))) | ||
64 | --- out | ||
65 | 9.007199254741e+15 | ||
66 | 9007199254740992 | ||
67 | 9007199254740992 | ||