bcpow
(PHP 4, PHP 5, PHP 7, PHP 8)
bcpow — 任意精度數字的乘方
說明
bcpow(string
$num
, string $exponent
, ?int $scale
= null
): string
num
的 exponent
次方運算。
參數
-
num
-
string 型別的底數。
-
exponent
-
string 型別的指數。 如果指數不是整數,將被截斷。 指數的有效範圍取決於平臺,但起碼支援
-2147483648
到2147483647
的範圍。 -
scale
-
此可選參數用於設定結果中小數點后的小數位數。也可通過使用 bcscale() 來設定全域性預設的小數位數,用於所有函式。如果未設定,則預設為
0
。
返回值
返回字串型別的結果。
更新日誌
版本 | 說明 |
---|---|
7.3.0 | 現在 bcpow() 可以按想要的小數點位數返回數字。 而之前,返回的數字會忽略尾隨零(trailing decimal zeroes)。 |
範例
示例 #1 bcpow() 示例
<?php
echo bcpow('4.2', '3', 2); // 74.08
?>
註釋
注意:
Before PHP 7.3.0 bcpow() may return a result with fewer digits after the decimal point than the
scale
parameter would indicate. This only occurs when the result doesn't require all of the precision allowed by thescale
. For example:示例 #2 bcpow() scale example
<?php
echo bcpow('5', '2', 2); // prints "25", not "25.00"
?>
參見
- bcpowmod() - Raise an arbitrary precision number to another, reduced by a specified modulus
- bcsqrt() - 任意精度數字的二次方根