summaryrefslogtreecommitdiff
path: root/ext/json/json_encoder.c
diff options
context:
space:
mode:
authorYasuo Ohgaki <yohgaki@ohgaki.net>2015-08-05 08:12:10 +0900
committerJakub Zelenka <bukka@php.net>2016-06-26 13:26:42 +0100
commitf943daf2d7eeed98d3ead5c05637c2ea8a2ff0e6 (patch)
tree869bb1269326a413167ce94e81aaa1136cfce71f /ext/json/json_encoder.c
parent8de8636a2b6dc331486284f1f037259bb7347768 (diff)
downloadphp-git-f943daf2d7eeed98d3ead5c05637c2ea8a2ff0e6.tar.gz
Initial patch for 0 mode float conversion. The magic number is better to be improved. Any suggestion where to define it?
Diffstat (limited to 'ext/json/json_encoder.c')
-rw-r--r--ext/json/json_encoder.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c
index f944b888c7..92ab413cf0 100644
--- a/ext/json/json_encoder.c
+++ b/ext/json/json_encoder.c
@@ -104,7 +104,11 @@ static inline void php_json_encode_double(smart_str *buf, double d, int options)
{
size_t len;
char num[PHP_JSON_DOUBLE_MAX_LENGTH];
- php_gcvt(d, (int)EG(precision), '.', 'e', &num[0]);
+ if (PG(serialize_precision) == -1) {
+ php_0cvt(d, 17, '.', 'e', num);
+ } else {
+ php_gcvt(d, PG(serialize_precision), '.', 'e', num);
+ }
len = strlen(num);
if (options & PHP_JSON_PRESERVE_ZERO_FRACTION && strchr(num, '.') == NULL && len < PHP_JSON_DOUBLE_MAX_LENGTH - 2) {
num[len++] = '.';