From d43297d51de909db9d8d6ef51da77e6becfbc81b Mon Sep 17 00:00:00 2001 From: Akhilbisht798 Date: Thu, 3 Oct 2024 12:06:11 +0530 Subject: [PATCH] changed nf function to handle double --- src/utilities/string_functions.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utilities/string_functions.js b/src/utilities/string_functions.js index 33c9d9ff0c..5208f4ca9e 100644 --- a/src/utilities/string_functions.js +++ b/src/utilities/string_functions.js @@ -305,10 +305,12 @@ function doNf(num, left, right) { let result = rightPart ? leftPart + '.' + rightPart : leftPart; return isNegative ? '-' + result : result; } else { - let roundedOff = num.toFixed(right); - [leftPart, rightPart] = roundedOff.toString().split('.'); + let roundedNum = Math.round(num * Math.pow(10, right)); + roundedNum = roundedNum / Math.pow(10, right); + [leftPart, rightPart] = roundedNum.toString().split('.'); leftPart = leftPart.padStart(left, '0'); - let result = typeof rightPart === 'undefined' ? leftPart : leftPart + '.' + rightPart; + let result = typeof rightPart === 'undefined' ? + leftPart : leftPart + '.' + rightPart.padEnd(right, '0'); return isNegative ? '-' + result : result; } }