<?php
/**
*精确加法
*@param[type]$a[description]
*@param[type]$b[description]
*/
functionmath_add($a,$b,$scale='2'){
returnbcadd($a,$b,$scale);
}
/**
*精确减法
*@param[type]$a[description]
*@param[type]$b[description]
*/
functionmath_sub($a,$b,$scale='2'){
returnbcsub($a,$b,$scale);
}
/**
*精确乘法
*@param[type]$a[description]
*@param[type]$b[description]
*/
functionmath_mul($a,$b,$scale='2'){
returnbcmul($a,$b,$scale);
}
/**
*精确除法
*@param[type]$a[description]
*@param[type]$b[description]
*/
functionmath_div($a,$b,$scale='2'){
returnbcdiv($a,$b,$scale);
}
/**
*精确求余/取模
*@param[type]$a[description]
*@param[type]$b[description]
*/
functionmath_mod($a,$b){
returnbcmod($a,$b);
}
/**
*比较大小
*@param[type]$a[description]
*@param[type]$b[description]
*大于返回1等于返回0小于返回-1
*/
functionmath_comp($a,$b,$scale='5'){
returnbccomp($a,$b,$scale);//比较到小数点位数
}
echomath_add('3.445','3.444')."\n";//加6.88
echomath_sub('3.445','3.444')."\n";//减0.00
echomath_mul('3.445','3.444')."\n";//乘11.86
echomath_div('3.445','3.444')."\n";//除1.00
echomath_mod('3.445','3.444')."\n";//取模0
echomath_comp('3.445','3.444')."\n";//比较1
echomath_add('3.445','3.444','3')."\n";//加6.889
echomath_sub('3.445','3.444','3')."\n";//减0.001
echomath_mul('3.445','3.444','3')."\n";//乘11.864
echomath_div('3.445','3.444','3')."\n";//除1.000
echomath_mod('3.445','3.444')."\n";//取模0
echomath_comp('3.445','3.444')."\n";//比较1
?>
|