bcmul
(PHP 4, PHP 5, PHP 7, PHP 8)
bcmul — 兩個任意精度數字乘法計算
說明
bcmul(string
$num1
, string $num2
, ?int $scale
= null
): string
num1
乘以 num2
。
參數
-
num1
-
字串型別的左運算元。
-
num2
-
字串型別的右運算元。
-
scale
-
此可選參數用於設定結果中小數點后的小數位數。也可通過使用 bcscale() 來設定全域性預設的小數位數,用於所有函式。如果未設定,則預設為
0
。
返回值
返回字串型別的結果。
更新日誌
版本 | 說明 |
---|---|
8.0.0 |
現在 scale 可以為 null。
|
7.3.0 | 現在 bcmul() 可以按想要的小數點位數返回數字。 而之前,返回的數字會忽略尾隨零(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"
?>