Home >Backend Development >PHP Tutorial >PHP - How to set or get the default precision parameter for all bc math functions using the bcscale() function?
In PHP, the bcscale() function is used to set the default parameters for all bc math function. This function sets the default scale parameter for all subsequent calls to BC math functions if no scale parameter is explicitly specified.
int bcscale($scale)
$bcscale() The parameter accepts only one parameter, which is a required integer type parameter. This parameter represents the number of digits after the decimal point. The default value is 0.
$bcscale() The function returns the old precision value.
<?php // default scale : 5 bcscale(5); // The default scale value as 5 echo bcadd('107', '6.5596'), ""; // this is not the same without bcscale() echo bcadd('107', '6.55957', 1), ""; // the default scale value as 5 echo bcadd('107', '6.55957'), ""; ?>
113.55960 113.5 113.55957
<?php // set default scale 5 bcscale(5); // set the default scale value as 5 echo bcadd('107', '6.5596'), ""; // this is not the same without bcscale() echo bcadd('107', '6.55957', 1), ""; // Changed the default scale value bcscale(3); // the default scale value as 5 echo bcadd('107', '6.55957'), ""; ?>
113.55960 113.55 113.559
The above is the detailed content of PHP - How to set or get the default precision parameter for all bc math functions using the bcscale() function?. For more information, please follow other related articles on the PHP Chinese website!