PHP – 如何使用 bcscale() 函数设置或获取所有 bc 数学函数的默认精度参数?
在 PHP 中,**bcscale()** 函数用于设置所有 **bc 数学** **函数** 的默认精度参数。此函数为所有后续调用不显式指定精度参数的 bc 数学函数设置默认精度参数。
语法
int bcscale($scale)
参数
**bcscale()** 参数只接受单个参数,并且它是必须的整数类型参数。此参数表示小数点后数字的位数。其默认值为 0。
返回值
**bcscale()** 函数返回旧的精度值。
示例 1
<?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
示例 2
<?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
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP