(PHP 4, PHP 5, PHP 7, PHP 8)
bcmul — 兩個(gè)任意精度數字乘法計算
$num1
, string $num2
, ?int $scale
= null
): string
num1
乘以 num2
。
num1
字符串類(lèi)型的左操作數。
num2
字符串類(lèi)型的右操作數。
scale
此可選參數用于設置結果中小數點(diǎn)后的小數位數。也可通過(guò)使用
bcscale() 來(lái)設置全局默認的小數位數,用于所有函數。如果未設置,則默認為 0
。
返回字符串類(lèi)型的結果。
版本 | 說(shuō)明 |
---|---|
8.0.0 |
現在 scale 可以為 null。
|
7.3.0 | 現在 bcmul() 可以按想要的小數點(diǎn)位數返回數字。 而之前,返回的數字會(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 thescale
. For example:示例 #2 bcmul() scale example
<?php
echo bcmul('5', '2', 2); // prints "10", not "10.00"
?>