Friday, 13 August 2021

PHP BCADD() && Fatal error: Uncaught Error: Call to undefined function bcadd()

 https://www.geeksforgeeks.org/php-bcadd-function/

https://stackoverflow.com/questions/51094183/fatal-error-uncaught-error-call-to-undefined-function-bcadd

PHP does not recognize "bcadd()" gives the error. "bcadd()" function is included in "bcmath" PHP extention.

Just installing the relevant bcmath extension would solved the issue.

sudo apt-get install php7.<Your PHP version>-bcmath

Please note, you should find the correct version of bcmath extension according to your PHP version. And restart apache

sudo service apache2 restart

PHP | bcadd() Function

  • Last Updated : 19 Apr, 2018

The bcadd() function in PHP is an inbuilt function and is used to add two arbitrary precision numbers. This function accepts two arbitrary precision numbers as strings and returns the addition of the two numbers after scaling the result to a specified precision.

Syntax:

string bcadd ( $num_str1, $num_str2, $scaleVal)

Program 1:

<?php
// PHP program to illustrate bcadd() function
   
// input numbers with arbitrary precision
$num_str1 = "3";
$num_str2 = "11.222";
   
// calculates the addition of
// the two numbers when $scaleVal is
// not specified
$res = bcadd($num_str1, $num_str2);
  
echo $res;
   
?>

Output:

14

Program 2:

<?php
// PHP program to illustrate bcadd() function
   
// input numbers with arbitrary precision
$num_str1 = "3";
$num_str2 = "11.222";
  
// scale value
$scaleVal = 4;
   
// calculates the addition of the two
// numbers when $scaleVal is specified
$res = bcadd($num_str1, $num_str2, $scaleVal);
  
echo $res;
   
?>

Output:

14.2220


No comments:

Post a Comment