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
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources