bcmul

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

bcmul兩個(gè)任意精度數(shù)字乘法計(jì)算

說(shuō)明

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

num1 乘以 num2。

參數(shù)

num1

字符串類(lèi)型的左操作數(shù)。

num2

字符串類(lèi)型的右操作數(shù)。

scale

此可選參數(shù)用于設(shè)置結(jié)果中小數(shù)點(diǎn)后的小數(shù)位數(shù)。也可通過(guò)使用 bcscale() 來(lái)設(shè)置全局默認(rèn)的小數(shù)位數(shù),用于所有函數(shù)。如果未設(shè)置,則默認(rèn)為 0。

返回值

返回字符串類(lèi)型的結(jié)果。

更新日志

版本 說(shuō)明
8.0.0 現(xiàn)在 scale 可以為 null。
7.3.0 現(xiàn)在 bcmul() 可以按想要的小數(shù)點(diǎn)位數(shù)返回?cái)?shù)字。 而之前,返回的數(shù)字會(huì)忽略尾隨零(trailing decimal zeroes)。

范例

示例 #1 bcmul() 示例

<?php
echo bcmul('1.34747474747''35'3); // 47.161
echo bcmul('2''4'); // 8
?>

注釋

注意:

Before PHP 7.3.0 bcmul() may return a result with fewer digits after the decimal point than the scale parameter would indicate. This only occurs when the result doesn't require all of the precision allowed by the scale. For example:

示例 #2 bcmul() scale example

<?php
echo bcmul('5''2'2);     // prints "10", not "10.00"
?>

參見(jiàn)

  • bcdiv() - 兩個(gè)任意精度的數(shù)字除法計(jì)算