Fonction : Si un nombre et negatif

Fonction : Si un nombre et negatif - PHP - Programmation

Marsh Posté le 24-02-2006 à 21:23:31    

Salut tout me monde !!
 
VOila je cherche une fonction ou autre permettant de tester si un nombre et negatif ou pas ;)
 
Merci par avance !

Reply

Marsh Posté le 24-02-2006 à 21:23:31   

Reply

Marsh Posté le 24-02-2006 à 21:29:05    

if($nombre<0) echo "nombre négatif!";
la doc php est sur php.net

Reply

Marsh Posté le 24-02-2006 à 21:44:12    

Code :
  1. if(substr((string)$nombre, 0, 1) == '-') echo "négatif... peut être";


 
:o


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 07-12-2015 à 16:39:53    

Désolé du déterage :D mais voici une fonction meilleure, car je cherchais et voila :
 

Code :
  1. function isPositifInteger($var)
  2. {
  3.     return (is_int($var) && $var > -1) ? true : false;
  4. }


---------------
“ Un avis d’un homme non avisé ne doit jamais être pris en compte par un homme avisé. ” Jean Plancher, 1810, Taverne « Chez Bonaparte »
Reply

Marsh Posté le 07-12-2015 à 16:49:02    

Orission a écrit :

Désolé du déterage :D mais voici une fonction meilleure, car je cherchais et voila :

 
Code :
  1. function isPositifInteger($var)
  2. {
  3.     return is_int($var) && $var > -1
  4. }



FYP :o


Message édité par gatsu35 le 07-12-2015 à 16:49:40
Reply

Marsh Posté le 07-12-2015 à 16:49:19    

Il n'a pas spécifié que le nb devait être un entier :o


---------------
Astres, outil de help-desk GPL : http://sourceforge.net/projects/astres, ICARE, gestion de conf : http://sourceforge.net/projects/icare, Outil Planeta Calandreta : https://framalibre.org/content/planeta-calandreta
Reply

Marsh Posté le 07-12-2015 à 19:19:16    

is_numeric :)

Reply

Marsh Posté le 19-01-2016 à 15:48:13    

$var >= 0 pas $var > -1 [:mimiax:5]  
Pourquoi faire simple ....

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed