Home  >  Article  >  Backend Development  >  PHP - How to set or get the default precision parameter for all bc math functions using the bcscale() function?

PHP - How to set or get the default precision parameter for all bc math functions using the bcscale() function?

王林
王林forward
2023-08-18 23:09:181076browse

PHP - 如何使用bcscale()函数设置或获取所有bc数学函数的默认精度参数?

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.

Syntax

int bcscale($scale)

Parameters

$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.

Return value

$bcscale() The function returns the old precision value.

Example 1

<?php
   // default scale : 5
   bcscale(5);

   // The default scale value as 5
   echo bcadd(&#39;107&#39;, &#39;6.5596&#39;), "";

   // this is not the same without bcscale()
   echo bcadd(&#39;107&#39;, &#39;6.55957&#39;, 1), "";

   // the default scale value as 5
   echo bcadd(&#39;107&#39;, &#39;6.55957&#39;), "";
?>

Output

113.55960 113.5 113.55957

The Chinese translation of Example 2

is:

Example 2

<?php
   // set default scale 5
   bcscale(5);

   // set the default scale value as 5
   echo bcadd(&#39;107&#39;, &#39;6.5596&#39;), "";

   // this is not the same without    bcscale()
   echo bcadd(&#39;107&#39;, &#39;6.55957&#39;, 1), "";

   // Changed the default scale value
   bcscale(3);

   // the default scale value as 5
   echo bcadd(&#39;107&#39;, &#39;6.55957&#39;), "";
?>

Output

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete