遷移伺服器後出現 Call to undefined function bcmul(),原因是缺少 php-bcmath 擴充套件。bcmath 提供任意精度數學運算,常用於金流加密計算。
yum install php-bcmath
安裝完成後重啟 Apache/php-fpm 即可。
yum update
yum install php53-bcmath
先更新系統套件,再安裝對應 PHP 版本的 bcmath。
| 函數 | 說明 |
|---|---|
bcadd($a, $b, $scale) | 高精度加法 |
bcsub($a, $b, $scale) | 高精度減法 |
bcmul($a, $b, $scale) | 高精度乘法 |
bcdiv($a, $b, $scale) | 高精度除法 |
bcmod($a, $b) | 高精度取模 |
bcpow($a, $b, $scale) | 高精度冪運算 |
bcscale($scale) | 設定全域預設小數位數 |
<?php
echo bcmul('1.34747474747', '35', 3); // 47.161
echo bcmul('2', '4'); // 8
bcscale(2);
echo bcdiv('10', '3'); // 3.33
?>
[bcmath]
bcmath.scale = 0 ; 預設小數位數