Home > Backend Development > PHP Tutorial > 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?

王林
Release: 2023-08-19 06:02:01
forward
1180 people have browsed it

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)
Copy after login

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;), "";
?>
Copy after login

Output

113.55960 113.5 113.55957
Copy after login

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;), "";
?>
Copy after login

Output

113.55960 113.55 113.559
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template