What is bcpow in PHP?

bcpow is a function in PHP that calculates the value of the arbitrary precision number raised to the power of another number.

Syntax

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

Parameters

  • num - It is the base number. num is of type string.

  • exp - It is the exponent. exp is of the integer type.

  • scale - variable of type int. It is an optional parameter. scale is used to set the number of digits after the decimal place in the result. The default value of scale is 0.

Return value

The function returns the value of num raised to the exp. The value returned is of type string.

Code

<?php
$num1 = '4.2';
$num2 = '3';
echo bcpow($num1, $num2);
echo bcpow($num1, $num2, 2);
?>

Expected output

74
74.08

Free Resources