FrostiE Posted May 15, 2007 Share Posted May 15, 2007 Hey, Was hoping you people could help me... What I'm trying to do, is to check whether a divided number is a integer or a fraction. A number gets divided by a incrementing for integer. I tried ctype_digit but it doesn't seem to work with any divided result. If you could help, I would really appreciate it ! Link to comment https://forums.phpfreaks.com/topic/51511-solved-checking-if-a-divided-number-isnt-a-fraction/ Share on other sites More sharing options...
Orio Posted May 15, 2007 Share Posted May 15, 2007 Use is_float() or is_int(). Orio. Link to comment https://forums.phpfreaks.com/topic/51511-solved-checking-if-a-divided-number-isnt-a-fraction/#findComment-253673 Share on other sites More sharing options...
MadTechie Posted May 15, 2007 Share Posted May 15, 2007 what about <?php $x = 1.8; if(is_int($x)) { echo "integer "; }else{ echo "fraction"; } ?> EDIT: Ahh beat me Link to comment https://forums.phpfreaks.com/topic/51511-solved-checking-if-a-divided-number-isnt-a-fraction/#findComment-253674 Share on other sites More sharing options...
Psycho Posted May 15, 2007 Share Posted May 15, 2007 Or there's always the mod Arithmetic operator % (i.e. it computes the remainder). If the mod is anything other than 0 then it is not a whole number: if ($x % $y) { echo "Fraction"; } else { echo "Integer"; } Link to comment https://forums.phpfreaks.com/topic/51511-solved-checking-if-a-divided-number-isnt-a-fraction/#findComment-253690 Share on other sites More sharing options...
FrostiE Posted May 15, 2007 Author Share Posted May 15, 2007 Ahh thanks ! Somehow managed to overlook the is_int function. Link to comment https://forums.phpfreaks.com/topic/51511-solved-checking-if-a-divided-number-isnt-a-fraction/#findComment-253700 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.