Repository: jsonata-js/jsonata (js)

Issue:
$formatNumber function returns NaN.00 when null in input
Hi,

We are using formatNumber to return an amount field properly formatted. But instead we are getting a "-NaN.00". 

Example:
$formatNumber($number(Account.Order[0].Product[2].Price), "#0.00")
returns "-NaN.00"
in the Account example of TryJSONata.

The expected behavior is it should return a null since the inside evaluation will return a null.

Pull request description:
handle undefined inputs in $formatNumber
Add usual `undefined` handling to `$formatNumber` function

Resolves #165 

Patch:
diff --git a/jsonata.js b/jsonata.js
index 02b689c..d4da49f 100644
--- a/jsonata.js
+++ b/jsonata.js
@@ -3570,6 +3570,11 @@ var jsonata = (function() {
      * @returns {String} The formatted string
      */
     function functionFormatNumber(value, picture, options) {
+        // undefined inputs always return undefined
+        if(typeof value === 'undefined') {
+            return undefined;
+        }
+
         var defaults = {
             "decimal-separator": ".",
             "grouping-separator": ",",


Test patch:
diff --git a/test/test-suite/groups/function-formatNumber/case036.json b/test/test-suite/groups/function-formatNumber/case036.json
new file mode 100644
index 0000000..8a864ff
--- /dev/null
+++ b/test/test-suite/groups/function-formatNumber/case036.json
@@ -0,0 +1,6 @@
+{
+    "expr": "$formatNumber(foo, '#0.00')",
+    "dataset": null,
+    "bindings": {},
+    "undefinedResult": true
+}
\ No newline at end of file