From f7cd4af089eac108716bb8336221e63b295f4d10 Mon Sep 17 00:00:00 2001 From: Priyansh Date: Sat, 6 Mar 2021 23:44:15 +0530 Subject: better add function --- bin/index.js | 4 ++-- 1 file 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.'); } -- cgit v1.2.3