(PHP 4, PHP 5, PHP 7, PHP 8)
bcmul — 2つの任意精度数値の乗算を行う
num1
左オペランドを表す文字列。
num2
右オペランドを表す文字列。
scale
null
, it will default to the default scale set with bcscale(),
or fallback to the value of the
bcmath.scale
INI directive.
結果を文字列で返します。
This function throws a ValueError in the following cases:
num1
or num2
is not a well-formed BCMath numeric string.
scale
is outside the valid range.
バージョン | 説明 |
---|---|
8.0.0 |
scale は、nullable になりました。
|
7.3.0 | bcmul() 関数が、指定されたスケールの数値を返すようになりました。 これより前のバージョンでは、 返される数値の末尾が 0埋め されることなく、省略される可能性がありました。 |
例1 bcmul() の例
<?php
echo bcmul('1.34747474747', '35', 3); // 47.161
echo bcmul('2', '4'); // 8
?>
注意:
PHP 7.3.0 より前のバージョンでは、 bcmul() は
scale
引数で指定したものより少ない桁数を返す可能性がありました。 これはscale
で許された精度が不要な場合にだけ起きていました。 たとえば、以下のような場合です:例2 bcmul() で scale を指定する例
<?php
echo bcmul('5', '2', 2); // prints "10", not "10.00"
?>