bcmul

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

bcmul2つの任意精度数値の乗算を行う

説明

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

num1num2 を掛けます。

パラメータ

num1

左オペランドを表す文字列。

num2

右オペランドを表す文字列。

scale
This parameter is used to set the number of digits after the decimal place in the result. If 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"
?>

参考

  • bcdiv() - 2つの任意精度数値で除算を行う