js精确计算浮点数相加

const payPrice= (row.payPrice.toString().split(".")[1] || "").length;
        const cash= (row.cash.toString().split(".")[1] || "").length;
        const baseNum = Math.pow(10, Math.max(payPrice, cash));
        return (row.payPrice * baseNum + row.cash * baseNum) / baseNum;
posted @ 2024-06-14 00:48  猝死的路上  阅读(35)  评论(0编辑  收藏  举报