php8.5
Home/ Manual/ bc / functions/ bcdiv

bcdiv

PHP function Edit on GitHub ✎

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

Divide two arbitrary precision numbers

Description

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

Divides num1 by num2.

Parameters

num1

The dividend, as a string.

num2

The divisor, as a string.

Return Values

Returns the result of the division as a string.

This function throws a DivisionByZeroError exception if num2 is 0.

Changelog

VersionDescription
8.0.0scale is now nullable.
8.0.0Dividing by 0 now throws a DivisionByZeroError exception instead of returning null.

Examples

bcdiv() example

php
<?php

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

?>

See Also

Source: reference/bc/functions/bcdiv.xml · from the official PHP manual (php/doc-en)