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

bccomp

PHP function Edit on GitHub ✎

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

Compare two arbitrary precision numbers

Description

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

Compares num1 to num2 and returns the result of the comparison as an integer.

Return Values

Returns 0 if both operands are equal, 1 if num1 is greater than num2, -1 otherwise.

Changelog

VersionDescription
8.0.0scale is now nullable.

Examples

bccomp() example

php
<?php

echo bccomp('1', '2') . "\n";   // -1
echo bccomp('1.00001', '1', 3); // 0
echo bccomp('1.00001', '1', 5); // 1

?>

See Also

  • BcMath\Number::compare

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