函式名:bcpow()
適用版本:PHP 4, PHP 5, PHP 7
函式用法:bcpow() 函式用於計算任意精度的數字的乘方。
語法:bcpow(string $left_operand, string $right_operand, int $scale = 0): string
引數:
- $left_operand (必填):要計算乘方的基數,必須為一個字串型別的數值。
- $right_operand (必填):指數,必須為一個字串型別的數值。
- $scale (可選):結果的小數點後的位數,預設值為0。
返回值:返回一個字串型別的數字結果。
示例:
$base = "2"; // 基數
$exponent = "10"; // 指數
$scale = 2; // 結果的小數點後的位數
$result = bcpow($base, $exponent, $scale);
echo "2的10次方是:".$result; // 輸出:2的10次方是:1024.00
說明:在上述示例中,我們將基數設定為2,指數設定為10,並將結果的小數點後的位數設定為2。bcpow() 函式將計算 2 的 10 次方,並返回結果為字串型別的數字 "1024.00"。