Change language

PHP Bccomp () Function

Syntax:
int bccomp ($num_str1, $num_str2, $scaleVal)
Parameters:This function takes three parameters, as shown in the above syntax and explained below.
  • $num_str1 : This parameter is of type string and represents the left-hand operand, or one of the two numbers among which we want to perform the comparison. This parameter is required.
  • $num_str2 : This parameter is of type string and represents the correct operand or one of the two numbers among which we want to perform the comparison. This parameter is required.
  • $scaleVal : This parameter is int and is optional. This parameter reports the number of digits after the decimal places to be used in the comparison. The default value for this parameter is zero.
Return Value:This function returns an integer value based on a comparison of two numbers $num_str1 and $num_str2. If both numbers are equal, then this function returns zero. If $num_str1 is greater than $num_str2 this function returns 1, and if $num_str1 is less than $num_str2 this function returns -1.Examples:
Input: $num_str1 = 3.22, $num_str2 = 3 Output: 0 Explanation : Since the parameter $scaleVal is not specified so no digits after decimal is used in comparison. So, the value of first parameter which is 3.22 will be treated as 3 and hence both parameters are equal. Input: $num_str1 = 3.222, $num_str2 = 3, $scaleVal = 2 Output: 1 Input: $num_str1 = 3, $num_str2 = 3.222, $scaleVal = 2 Output: -1
Below programs illustrate the function bccomp() in PHP:Program 1:
// PHP program for illustrating the bccomp() function 
// enter numbers $num_str1 = "3.12" ; $num_str2 = "3" ;  
// compares the two
// numbers when $scaleVal is not specified $res = bccomp ( $num_str1 , $num_str2 , 2);  
// both parameters are equal echo $res ;  
?>
Output:
0
Program 2:
// PHP program for illustrating the bccomp() function 
// enter numbers $num_str1 = "3.12" ; $num_str2 = "3" ;  
// scale value $scaleVal = 2;  
// compares the two
// numbers when $scaleVal is specified $res = bccomp ( $num_str1 , $num_str2 , $scaleVal );  
// the first parameter is greater than the second echo $res ;  
?>
Output:
1
Program 3:
// PHP program for illustrating the bccomp() function 
// enter numbers $num_str1 = "3" ; $num_str2 = "3.12" ;  
// scale value $scaleVal = 2;  
// compares the two
// numbers when $scaleVal is specified $res = bccomp ( $num_str1 , $num_str2 , $scaleVal );  
// the first parameter is less than the second echo $res ;  
?>
Output:
-1
Link:
http://php.net/manual /en/function.bccomp.php

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically