Skip to content

Commit

Permalink
changed nf function to handle double
Browse files Browse the repository at this point in the history
  • Loading branch information
Akhilbisht798 committed Oct 3, 2024
1 parent 0e3df94 commit d43297d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/utilities/string_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit d43297d

Please sign in to comment.