From da3151816ab96e3d08c43cb5aca5d4666359ad2b Mon Sep 17 00:00:00 2001 From: kianomoomi Date: Fri, 24 Dec 2021 14:50:20 +0330 Subject: [PATCH 1/2] fix value() function --- numeral.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numeral.js b/numeral.js index 22726c9e..54da5346 100644 --- a/numeral.js +++ b/numeral.js @@ -605,7 +605,7 @@ return output; }, value: function() { - return this._value; + return parseFloat(Number.parseFloat(this._value).toPrecision(8)); }, input: function() { return this._input; From f8cc7e66e851a5d531efe03b585a97be7ee65c19 Mon Sep 17 00:00:00 2001 From: kianomoomi Date: Fri, 24 Dec 2021 17:12:08 +0330 Subject: [PATCH 2/2] fix negative number formatting to a specific precision --- numeral.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/numeral.js b/numeral.js index 54da5346..1059583c 100644 --- a/numeral.js +++ b/numeral.js @@ -395,7 +395,10 @@ power = Math.pow(10, boundedPrecision); // Multiply up by precision, round accurately, then divide and use native toFixed(): - output = (roundingFunction(value + 'e+' + boundedPrecision) / power).toFixed(boundedPrecision); + output = (roundingFunction(Math.abs(value) + 'e+' + boundedPrecision) / power).toFixed(boundedPrecision); + if(value < 0){ + output = '-' + output + } if (optionals > maxDecimals - boundedPrecision) { optionalsRegExp = new RegExp('\\.?0{1,' + (optionals - (maxDecimals - boundedPrecision)) + '}$');