php涉及金钱的计算【BC高精确度函数库】

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_40012791/article/details/95355437

1、两个高精度数比较
 *工作中遇到一种情况,0.00 != 0
 *int bccomp ( string $left_operand , string $right_operand [, int $scale ] )
 *$left=$right 返回 0
 *$left<$right 返回 -1
 *$left>$right 返回 1
 *$scale 小数点位数


 2、两个高精度数相加
 *string bcadd ( string $left_operand , string $right_operand [, int $scale ] )
 *$scale 返回的小数点个数

 3、两个高精度数相减
 *sstring bcsub ( string $left_operand , string $right_operand [, int $scale ] )
 *$scale 返回的小数点个数

 4、两个高精度数求余/取模 (10/3=3余1,这个函数返回1)
 *string bcmod ( string $left_operand , string $modulus )

 5、两个高精度数相除
 *string bcdiv ( string $left_operand , string $right_operand [, int $scale ] )
 *$scale小数点位数默认为 0

 6、两个高精度数相乘
 *string bcmul ( string $left_operand , string $right_operand [, int $scale ] )
 *$scale小数点位数默认为 0

 7、两个高精度数的次方值( 2³=8=bcpow(2,3) 
 *string bcpow ( string $left_operand , string $right_operand [, int $scale ] )
 *$scale小数点位数默认为 0

 8、求高精度数的平方根( √9=3=bcsqrt(9,2) 
 *string bcsqrt ( string $operand [, int $scale ] )
 *$scale小数点位数默认为 0

 9、设置bc函数的小数点位数
 *bool bcscale ( int $scale )
 *$scale小数点位数默认为 0 

 注意:一般在计算前设置好精度,后面的计算就不需要设置小数位数了;设置之后,再进行设置,无法覆盖;

猜你喜欢

转载自blog.csdn.net/qq_40012791/article/details/95355437
今日推荐