From ead22d9d19d242354ee91b017d68305d0176e807 Mon Sep 17 00:00:00 2001 From: Dan Mooney Date: Thu, 20 Oct 2022 12:54:28 -0500 Subject: [PATCH 1/3] Fix niceNum implementation - Previous state was not locale-dependent --- js/script.js | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/js/script.js b/js/script.js index e95bdb0..7c77ecd 100644 --- a/js/script.js +++ b/js/script.js @@ -572,26 +572,11 @@ if (/MSIE [5-9]/.test(navigator.userAgent)) { app.filter("niceNum", function () { return function (num) { - var niceNum = ""; - var step = 1; - - while (num >= 1) { - rest = num % 1000; - - //Put it in a nice string - if (num > 1000) { - if (rest < 10) { - rest = "00" + rest; - } else if (rest < 100) { - rest = "0" + rest; - } - } - - niceNum = rest + "'" + niceNum; - num = Math.floor(num / 1000); + if (!num || isNaN(num)) { + return 0; } - return niceNum === "" ? "0" : niceNum.substring(0, niceNum.length - 1); + return parseInt(num, 10).toLocaleString(); }; }); From 732d9b95a0d7a9d30d740fba4da688228815d07e Mon Sep 17 00:00:00 2001 From: Dan Mooney Date: Thu, 20 Oct 2022 13:05:26 -0500 Subject: [PATCH 2/3] Return string --- js/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/script.js b/js/script.js index 7c77ecd..705c6a8 100644 --- a/js/script.js +++ b/js/script.js @@ -572,8 +572,8 @@ if (/MSIE [5-9]/.test(navigator.userAgent)) { app.filter("niceNum", function () { return function (num) { - if (!num || isNaN(num)) { - return 0; + if (isNaN(num)) { + return '0'; } return parseInt(num, 10).toLocaleString(); From 1e06d5d837e19099097124bec06a13c7e4894421 Mon Sep 17 00:00:00 2001 From: Dan Mooney <30629803+danmooney2@users.noreply.github.com> Date: Wed, 19 Apr 2023 08:54:49 -0500 Subject: [PATCH 3/3] Throw error when argument passed to niceNum filter is NaN Co-authored-by: Harsh Singh <63696299+harshsingh32@users.noreply.github.com> --- js/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/script.js b/js/script.js index 705c6a8..0db6726 100644 --- a/js/script.js +++ b/js/script.js @@ -573,7 +573,7 @@ if (/MSIE [5-9]/.test(navigator.userAgent)) { app.filter("niceNum", function () { return function (num) { if (isNaN(num)) { - return '0'; + throw new Error("Input is not a number"); } return parseInt(num, 10).toLocaleString();