# HG changeset patch # User jbe # Date 1407692505 -7200 # Node ID 44344b4a52c1d51682c6c7a5ca4096a9a4fff7b0 # Parent 433fa98329ecc71ed1ec9005202eeb8ea147e94e Increase precision of exported floats to 16 decimal digits in json.export(...) diff -r 433fa98329ec -r 44344b4a52c1 libraries/json/json.c --- a/libraries/json/json.c Sun Aug 10 19:18:25 2014 +0200 +++ b/libraries/json/json.c Sun Aug 10 19:41:45 2014 +0200 @@ -1021,6 +1021,7 @@ int pretty; // pretty printing on? (i.e. printing with indentation) luaL_Buffer buf; // Lua buffer containing result string lua_Number num; // number to encode + char numstr[20]; // encoded number (sign, zero, point, 16 significant digits, and terminating NULL byte) const char *str; // string to encode size_t strlen; // length of string to encode size_t strpos ; // position in string or position of current key @@ -1093,9 +1094,8 @@ // throw error if number is positive or negative infinity: if (isinf(num)) return luaL_error(L, "JSON export not possible for infinite numbers"); // add Lua's string encoding of the number to the output buffer: - lua_pushvalue(L, json_export_value_idx); - lua_tostring(L, -1); - luaL_addvalue(&buf); + sprintf(numstr, "%.16g", num); + luaL_addstring(&buf, numstr); break; // value to encode is of type boolean: case LUA_TBOOLEAN: