From 0ff7ed2705580921d581bf5f32793d4f3e699f5b Mon Sep 17 00:00:00 2001 From: MoNam97 Date: Fri, 24 Dec 2021 22:27:04 +0330 Subject: [PATCH 1/2] #515 Solved --- numeral.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numeral.js b/numeral.js index 22726c9e..4350bba1 100644 --- a/numeral.js +++ b/numeral.js @@ -395,7 +395,7 @@ 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((value + 'e+' + boundedPrecision) -0.5)/ power).toFixed(boundedPrecision); if (optionals > maxDecimals - boundedPrecision) { optionalsRegExp = new RegExp('\\.?0{1,' + (optionals - (maxDecimals - boundedPrecision)) + '}$'); From 1c6b226be6c8e8878537c09864bd2e71c578ec84 Mon Sep 17 00:00:00 2001 From: MoNam97 Date: Fri, 24 Dec 2021 22:41:01 +0330 Subject: [PATCH 2/2] #505 Solved -a --- numeral.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/numeral.js b/numeral.js index 4350bba1..854c9e13 100644 --- a/numeral.js +++ b/numeral.js @@ -395,7 +395,17 @@ power = Math.pow(10, boundedPrecision); // Multiply up by precision, round accurately, then divide and use native toFixed(): - output = (roundingFunction((value + 'e+' + boundedPrecision) -0.5)/ power).toFixed(boundedPrecision); + output = (roundingFunction(value + 'e+' + boundedPrecision)/ power).toFixed(boundedPrecision); + + if (Number(output) > value){ + if (output.includes('.')) { + l = output.split('.')[1].length; + new_num = 10 **(-l); + new2_num = Number(output) - new_num; + output = new2_num.toString(); + } + output = (roundingFunction(output + 'e+' + boundedPrecision) / power).toFixed(boundedPrecision); + } if (optionals > maxDecimals - boundedPrecision) { optionalsRegExp = new RegExp('\\.?0{1,' + (optionals - (maxDecimals - boundedPrecision)) + '}$');