開發過程當中,普通的加減乘除基本能知足一些平常的開發須要,可是在一些須要高精度計算的開發中(例如和金錢相關的計算),咱們仍是須要用到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數學函數