bcpow

(PHP 4, PHP 5, PHP 7, PHP 8)

bcpow任意精度數(shù)字的乘方

說明

bcpow(string $num, string $exponent, ?int $scale = null): string

numexponent 次方運(yùn)算。

參數(shù)

num

string 類型的底數(shù)。

exponent

string 類型的指數(shù)。 如果指數(shù)不是整數(shù),將被截?cái)唷? 指數(shù)的有效范圍取決于平臺(tái),但起碼支持 -21474836482147483647 的范圍。

scale

此可選參數(shù)用于設(shè)置結(jié)果中小數(shù)點(diǎn)后的小數(shù)位數(shù)。也可通過使用 bcscale() 來設(shè)置全局默認(rèn)的小數(shù)位數(shù),用于所有函數(shù)。如果未設(shè)置,則默認(rèn)為 0

返回值

返回字符串類型的結(jié)果。

更新日志

版本 說明
7.3.0 現(xiàn)在 bcpow() 可以按想要的小數(shù)點(diǎn)位數(shù)返回?cái)?shù)字。 而之前,返回的數(shù)字會(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 the scale. 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() - 任意精度數(shù)字的二次方根