Repository: jsonata-js/jsonata (js)

Issue:
numeric precision should be 15 decimal digits, not 13
With the JavaScript implementation on try.jsonata.org I am getting only 13 decimal digits of precision with numeric data ... when I expected 15. I am observing this behavior in Chrome + FireFox + Safari. 

see http://try.jsonata.org/r1SPLIKjz

IEEE 754 double (binary64) gives you 53 bits of significand. This gives one a reliable 15 decimal digits of precision. 

[ If I invoke jsonata-1.1.1.js using the nashorn scripting engine of Java 1.8.0_152 then numeric data is retains its full IEEE value ... unless I explicitly call JSONata $string(). ]

Looks to me like the reason it is being chopped to 13 digits in the JavaScript implementation is with `functionString()`, where one sees the following:

    str = JSON.stringify(arg, function (key, val) {
                return (typeof val !== 'undefined' && val !== null &&
                           val.toPrecision && isNumeric(val)) ? 
                    Number(val.toPrecision(13)) :
                    (val && isFunction(val)) ? '' : val;`

My initial thought was/is that it would be best to leave the numbers alone and let `JSON.stringify()` handle it. Yet, there must have been some negative behavior that led to this code being added. 

Q: What was the issue that caused numbers to be treated this way? 

If there is a good reason for rounding to a specific decimal precision, then the precision should be set to 15, not 13. 




Pull request description:
$string should format numbers to 15 s.f.
Change numeric precision from 13 to 15 in function `$string`
resolves #194 

Patch:
diff --git a/jsonata.js b/jsonata.js
index 80bbecc..4505cb6 100644
--- a/jsonata.js
+++ b/jsonata.js
@@ -3074,7 +3074,7 @@ var jsonata = (function() {
             };
         } else
             str = JSON.stringify(arg, function (key, val) {
-                return (typeof val !== 'undefined' && val !== null && val.toPrecision && isNumeric(val)) ? Number(val.toPrecision(13)) :
+                return (typeof val !== 'undefined' && val !== null && val.toPrecision && isNumeric(val)) ? Number(val.toPrecision(15)) :
                     (val && isFunction(val)) ? '' : val;
             });
         return str;


Test patch:
diff --git a/test/test-suite/groups/function-string/case001.json b/test/test-suite/groups/function-string/case001.json
index e831829..5c0ed47 100644
--- a/test/test-suite/groups/function-string/case001.json
+++ b/test/test-suite/groups/function-string/case001.json
@@ -2,5 +2,5 @@
     "expr": "$string(22/7)",
     "dataset": "dataset5",
     "bindings": {},
-    "result": "3.142857142857"
+    "result": "3.14285714285714"
 }
\ No newline at end of file