bcdiv

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

bcdivDivide two arbitrary precision numbers

Опис

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

Divides num1 by num2.

Параметри

num1

The dividend, as a string.

num2

The divisor, as a string.

scale

Необов'язковий параметр, яким вказується кількість знаків після крапки в результаті. Якщо опущено, застосовується межа, що встановлена глобально функцією bcscale(), або ж 0, якщо межа ще не встановлена.

Значення, що повертаються

Returns the result of the division as a string.

Помилки/виключення

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.

This function throws a DivisionByZeroError exception if num2 is 0.

Журнал змін

Версія Опис
8.0.0 scale is now nullable.
8.0.0 Dividing by 0 now throws a DivisionByZeroError exception instead of returning null.

Приклади

Приклад #1 bcdiv() example

<?php

echo bcdiv('105', '6.55957', 3); // 16.007

?>

Прогляньте також

  • bcdivmod() - Get the quotient and modulus of an arbitrary precision number
  • bcmod() - Get modulus of an arbitrary precision number
  • bcmul() - Multiply two arbitrary precision numbers