(PHP 4, PHP 5, PHP 7, PHP 8)
bcpow — 任意精度數字的乘方
$num
, string $exponent
, ?int $scale
= null
): string
num
的 exponent
次方運算。
num
string 類(lèi)型的底數。
exponent
string 類(lèi)型的指數。 如果指數不是整數,將被截斷。
指數的有效范圍取決于平臺,但起碼支持
-2147483648
到 2147483647
的范圍。
scale
此可選參數用于設置結果中小數點(diǎn)后的小數位數。也可通過(guò)使用
bcscale() 來(lái)設置全局默認的小數位數,用于所有函數。如果未設置,則默認為 0
。
返回字符串類(lèi)型的結果。
版本 | 說(shuō)明 |
---|---|
7.3.0 | 現在 bcpow() 可以按想要的小數點(diǎn)位數返回數字。 而之前,返回的數字會(huì )忽略尾隨零(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"
?>