number-precision
number-precision copied to clipboard
能不能像jQuery那样链式操作呢
期望
NP.plus(0.1, 0.2).times(3)// = 0.9 not 0.9000000000000001
期望
NP.plus(0.1, 0.2).times(3)// = 0.9 not 0.9000000000000001
https://github.com/yungsun09/number-precision-chainable 你可以看下效果,但真用起来感觉会死(x
@yungsun09 number-precision-chainable 链式调用很棒。
我理解@gaolingyi-hadi 是希望使用的方法更易读,这里安利下 number-precision-macro,支持NPM((1+1)/2)这样的js表达式写法,而不用使用NP.divide(NP.plus(1, 1),2)。
建议官方采纳一下 defims/number-precision-macro
@yungsun09 number-precision-chainable 链式调用很棒。 我理解@gaolingyi-hadi 是希望使用的方法更易读,这里安利下 number-precision-macro,支持
NPM((1+1)/2)这样的js表达式写法,而不用使用NP.divide(NP.plus(1, 1))。
你这个真的很厉害了,我都没想过还能这么写,star了
Number.prototype.plus = function (arg) { return NP.plus(this, arg) } // 减法 Number.prototype.minus = function (arg) { return NP.minus(this, arg) } // 乘法 Number.prototype.times = function (arg) { return NP.times(this, arg) } // 除法 Number.prototype.divide = function (arg) { return NP.divide(this, arg) } // 四舍五入 Number.prototype.round = function (arg) { return NP.round(this, arg) } 可以在原型上面增加方法 这样就支持了,但是计算只能是一个参数 例如:NP.plus(0.1, 0.2).times(3),如果是NP.plus(0.1, 0.2).times(3,2), 再除以2无效