参考地址:php BC数学函数
/**
* @desc:精确加法
* @param [type] $a [description]
* @param [type] $b [description]
* @param int $scale 保留小数位数
* @return string
* @author:圣灵儿 2864934511@qq.com
* @date: 2020-10-28 09:13:29
*/
function math_add($a, $b, $scale = 0)
{
return bcadd($a.'', $b.'', $scale);
}
/**
* 精确减法
* @param [type] $a [description]
* @param [type] $b [description]
* @param int $scale 保留小数位数
* @return string
* @author:圣灵儿 2864934511@qq.com
* @date: 2020-10-28 09:13:29
*/
function math_sub($a, $b, $scale = 0)
{
return bcsub($a.'', $b.'', $scale);
}
/**
* 精确乘法
* @param [type] $a [description]
* @param [type] $b [description]
* @param int $scale 保留小数位数
* @return string
* @author:圣灵儿 2864934511@qq.com
* @date: 2020-10-28 09:13:29
*/
function math_mul($a, $b, $scale = 0)
{
return bcmul($a.'', $b.'', $scale);
}
/**
* 精确除法
* @param [type] $a [description]
* @param [type] $b [description]
* @param int $scale 保留小数位数
* @return string
* @author:圣灵儿 2864934511@qq.com
* @date: 2020-10-28 09:13:29
*/
function math_div($a, $b, $scale = 0)
{
return bcdiv($a.'', $b.'', $scale);
}
/**
* 精确求余/取模
* @param [type] $a [description]
* @param [type] $b [description]
* @return string
* @author:圣灵儿 2864934511@qq.com
* @date: 2020-10-28 09:13:29
*/
function math_mod($a, $b)
{
return bcmod($a.'', $b.'');
}
/**
* 比较大小
* @param [type] $a [description]
* @param [type] $b [description]
* 大于 返回 1 等于返回 0 小于返回 -1
* @param int $scale 保留小数位数
* @return string
* @author:圣灵儿 2864934511@qq.com
* @date: 2020-10-28 09:13:29
*/
function math_comp($a, $b, $scale = 0)
{
return bccomp($a.'', $b.'', $scale); // 比较到小数点位数
}