Thursday, October 16, 2025
HomeLanguagesPHP | bcpow() Function

PHP | bcpow() Function

The bcpow() function in PHP is an inbuilt function and is used to calculate the value of an arbitrary precision base number raised to another exponent number. This function accepts two arbitrary precision numbers as strings and returns the base number raised to exponent after scaling the result to a specified precision.

Syntax:

string bcpow ( $base, $exponent, $scaleVal )

Parameters: This function accepts three parameters as shown in the above syntax and explained below:

  • $base: This parameter is of string type and represents the base in which the power will be raised. This parameter is mandatory.
  • $exponent: This parameter is of string type and represents the exponent. This parameter is mandatory.
  • $scaleVal: This parameter is of int type and is optional. This parameter tells the number of digits that will appear after the decimal in the result of baseexponent. It’s default value is zero.

Return Value: This function returns the $base$exponent result as string.

Examples:

Input:  $base = 2, $exponent = 3 
Output: 8
Since the parameter $scaleVal is not specified so
no digits after decimal is appeared in the 
result after evaluating result

Input:  $base = 2, $exponent = 3, $scaleVal = 2
Output: 8
Note: Instead of 8.00, output of 8 is given. 
This is an exception in bc math functions.

Below programs illustrate the bcpow() function in PHP :

Program 1:




<?php
// PHP program to illustrate bcpow() function
   
// input numbers with arbitrary precision
$base = "2";
$exponent = "3"; 
   
// calculates the base^exponent
// the two numbers when $scaleVal is
// not specified
$res = bcpow($base, $exponent);
  
echo $res;
   
?>


Output:

2

Program 2:




<?php
// PHP program to illustrate bcpow() function
   
// input numbers with arbitrary precision
$base = "2";
$exponent = "3";
  
// scale value
$scaleVal = 4;
  
// calculates the base^exponent
// the two numbers when $scaleVal is
// specified 
$res = bcpow($base, $exponent, $scaleVal); 
  
echo $res;
?>


Output:

2

Reference:
http://php.net/manual/en/function.bcpow.php

Last Updated :
19 Apr, 2018
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS