aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPriyansh <[email protected]>2021-03-06 23:44:15 +0530
committerPriyansh <[email protected]>2021-03-06 23:44:15 +0530
commitf7cd4af089eac108716bb8336221e63b295f4d10 (patch)
tree822f89e1e2d1c65e8f0e1af056ccac53f2aee0d7
parent8b9de2d7ebea53ae767879082d3e04995f2cde89 (diff)
downloadcalculator-f7cd4af089eac108716bb8336221e63b295f4d10.tar.xz
calculator-f7cd4af089eac108716bb8336221e63b295f4d10.zip
better add function
-rw-r--r--bin/index.js4
1 files changed, 2 insertions, 2 deletions
diff --git a/bin/index.js b/bin/index.js
index fc8c1dc..6c1d14b 100644
--- a/bin/index.js
+++ b/bin/index.js
@@ -43,12 +43,12 @@ Command Help Example:
.option('rt', {
alias: 'round-to',
desc: 'Round upto the number of decimal places passed',
- type: 'number',
+ type: 'number'
}),
handler: function (args) {
if (args._.length === 2) {
const result = args._[1].split(',').reduce((a, b) => Number(a) + Number(b), 0)
- console.log(args.rt ? parseFloat(result.toFixed(args.rt)) : result)
+ console.log(args.rt ? Math.round((result + Number.EPSILON) * Math.pow(10, args.rt)) / Math.pow(10, args.rt) : result)
} else {
infoMessage.showError('add', 'needs a list of comma-separated numbers to be passed.');
}