★ wanayoo — archive 1999 http://fr.php.net/manual/fr/function.bccomp.phpNouvelle recherche | Portail wanayoo
PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links 
search for in the  
previousbcaddbcdivnext
Last updated: Tue, 09 Jul 2002
view the printer friendly version or the printer friendly version with notes or change language to English | Brazilian Portuguese | Czech | Dutch | Finnish | German | Hungarian | Italian | Japanese | Korean | Polish | Romanian | Russian | Slovak | Spanish | Swedish | Turkish

bccomp

(PHP 3, PHP 4 )

bccomp -- Compare deux nombres de grande taille.

Description

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

bccomp() compare l'opérande left_operand avec l'opérande right_operand et renvoie le résultat sous forme de valeur numérique (entier). Le paramètre optionnel scale est utilisé pour définir le nombre de chiffres après la virgule utilisés lors de la comparaison. Le résultat est 0 si les deux opérandes sont égales. Si l'opérande left_operand est plus grande que l'opérande right_operand, le résultat est 1. Si l'opérande left_operand est plus petite que l'opérande right_operand, le résultat est -1.

User Contributed Notes
bccomp
add a note about notes
victorvalley at gmx dot net
04-Nov-2002 07:51

Use the bccomp() function like this:

if ($result=(bccomp($number1,$number2)) < 0){
  // What to do if $number1 is lower than $number2
} else if ($result > 0) {
  // What to do if $number1 is greater than $number2
} else {
  // Guess what this will do?
  // This will happen if $number1 equals $number2!
}

This could be done in a different way with switch-case as well:

switch (bccomp($number1,$number2)){
  case -1:
   // $number1 < $number2
 break;
 case 0:
   // $number1 == $number2
 break;
 case 1:
   // $number1 > $number2
 break;
}

You don't have to set all 3 cases but it makes this example look longer :)

add a note about notes
previousbcaddbcdivnext
Last updated: Tue, 09 Jul 2002
show source | credits | stats | mirror sites
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by: nexen.net
Last updated: Tue Dec 3 04:12:42 2002 CET