2020-11-04 js 加减乘除精度运算

// js小数加减乘除时精度修正

export const floatObj = function () {

    //加法

    function add(a,b){

        return math.number(math.add(math.bignumber(a), math.bignumber(b))) ;

    };


    //减法

    function subtract(a,b){

        return math.number(math.subtract(math.bignumber(a), math.bignumber(b)));

    };


    // 乘法

    function multiply(a,b){

        return math.number(math.multiply(math.bignumber(a), math.bignumber(b)));

    };


    // 除法

    function divide(a,b){

        return math.number(math.divide(math.bignumber(a), math.bignumber(b)));

    };

    return {

    add: add,

    subtract: subtract,

    multiply: multiply,

    divide: divide

    }

}();

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。