I l@ve RuBoard Previous Section Next Section

bccomp

int bccomp(string left_operand, string right_operand, [int scale]) 

left_operand

First number to compare

right_operand

Second number to compare

scale

Number of decimal places

Compares two numbers.

Returns:

0 if the same; 1 or -1 if different

Description:

Compares the value of the first number with the value of the second number. The optional decimal-places argument specifies the number of decimal places to compare. For example, if the number of decimal places is 2, bccomp() would compare to only two decimal places, regardless of how the numbers diverged beyond this level. The function returns 0 if the numbers are the same, 1 if the first number is greater than the second, or -1 if the second number is greater than the first.

Version:

Existing since version 3.0

Example:

Compare two large numbers
$num1="12345.6789"; 
$num2="12345.6767"; 
echo bccomp($num1,$num2,2) . "\n"; 
echo bccomp($num1,$num2,4); 

Output: 
0 
1 
    I l@ve RuBoard Previous Section Next Section