bcadd

(PHP 4, PHP 5, PHP 7, PHP 8)

bcadd两个任意精度数字的加法计算

说明

bcadd(string $num1, string $num2, ?int $scale = null): string

num1num2 求和。

参数

num1

左操作数,字符串类型。

num2

右操作数,字符串类型。

scale

此可选参数用于设置结果中小数点后的小数位数。也可通过使用 bcscale() 来设置全局默认的小数位数,用于所有函数。如果未设置,则默认为 0

返回值

以字符串返回两个操作数求和之后的结果。

更新日志

版本 说明
8.0.0 现在 scale 可以为 null。

范例

示例 #1 bcadd() 示例

<?php

$a
= '1.234';
$b = '5';

echo
bcadd($a, $b); // 6
echo bcadd($a, $b, 4); // 6.2340

?>

参见

  • bcsub() - 两个任意精度数字的减法

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top