PHP | bcscale()函数

bcscale()函数是PHP中的内置函数。它为所有bc数学函数调用设置默认比例参数。当我们在程序中调用函数bcscale()时,在这个函数中传递的参数就变成了默认的比例因子,默认情况下是零。

null

语法:

int bcscale($scale)

参数: 此函数只接受一个参数 美元规模 并且是int类型,是必需的。此参数表示所有bc数学函数的函数调用结果中小数点后出现的位数。其默认值为零。

返回值: 此函数返回旧的比例值。

下面的程序演示了PHP中的bcscale()函数:

项目1:

<?php
// default scale : 3
bcscale(3);
// takes the default scale value as 3
// which is declared at the beginning
echo bcadd ( '111' , '6.55957' ), "" ; // 16.007
// this is not the same without bcscale()
echo bcadd ( '111' , '6.55957' , 1), "" ; // 16.007
//  takes the default scale value as 3
// which is declared at the beginning
echo bcadd ( '111' , '6.55957' ), "" ;
?>


输出:

117.559 
117.5 
117.559

项目2:

<?php
// default scale : 3
bcscale(5);
// takes the default scale value as 3
// which is declared at the beginning
echo bcadd ( '111' , '6.55957' ), "" ; // 16.007
// this is not the same without bcscale()
echo bcadd ( '111' , '6.55957' , 1), "" ; // 16.007
// default scale value changes
bcscale(2);
// takes the default scale value as 2
// which is declared
echo bcadd ( '111' , '6.55957' ), "" ;
?>


输出:

117.55957 
117.5 
117.55

参考: http://php.net/manual/en/function.bcscale.php

© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享