jq下进行乘法运算:
var num=accMul(0.123,2.21);//0.27183 num=decimal(num,2);//0.27 //精确乘法运算 function accMul(arg1,arg2){ var m=0,s1=arg1.toString(),s2=arg2.toString(); try{m+=s1.split(".")[1].length}catch(e){} try{m+=s2.split(".")[1].length}catch(e){} return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m); } //四舍五入保留两位小数(v的值是几保留几位小数) function decimal(num,v){ var vv = Math.pow(10,v); return Math.round(num*vv)/vv; }
php下进行乘法运算
$num= bcmul(1, 0.123456789, 8); //0.12345678备注bcmul(a, b,c)a,b代表数值,c则是运算后保留几位小数
$num = round($num, 2);//0.12
时间: 2024-11-05 18:44:23