开发过程当中,普通的加减乘除基本能知足一些平常的开发须要,可是在一些须要高精度计算的开发中(例如和金钱相关的计算),咱们仍是须要用到PHP的高精度的数字计算的。 那么在PHP中高精度计算的函数有哪些呢?php
PHP数学函数
- bcadd
- 2个任意精度数字的加法计算
- string bcadd ( string $left_operand , string $right_operand [, int $scale ] )
- left_operand 左操做数,字符串类型
- right_operand 右操做数,字符串类型
- scale 此可选参数用于设置结果中小数点后的小数位数。
- 也可经过使用 bcscale() 来设置全局默认的小数位数,用于全部函数。
- 返回值: 2个操做数求和以后的结果以字符串返回
- bcsub
- 2个任意精度数字的减法
- string bcsub ( string $left_operand , string $right_operand [, int $scale = int ] )
- bcmul
- 2个任意精度数字乘法计算
- string bcmul ( string $left_operand , string $right_operand [, int $scale = int ] )
- bcdiv
- 2个任意精度的数字除法计算
- string bcdiv ( string $left_operand , string $right_operand [, int $scale = int ] )
- bcmod
- 对一个任意精度数字取模
- string bcmod ( string $left_operand , string $modulus )
- 返回值: 返回字符串类型取模后结果,若是系数为0则返回null
- bccomp
- 比较两个任意精度的数字
- int bccomp ( string $left_operand , string $right_operand [, int $scale = int ] )
- 返回值: 若是两个数相等返回0, 左边的数left_operand比较右边的数right_operand大返回1, 不然返回-1.
- bcpow
- 任意精度数字的乘方
- string bcpow ( string $left_operand , string $right_operand [, int $scale ] )
- bcsqrt
- 任意精度数字的二次方根
- string bcsqrt ( string $operand [, int $scale ] )
以上就是PHP开发中经常使用到的精度相关的函数。函数
参考阅读
- BC数学函数