jermaindefoe Posted November 23, 2009 Share Posted November 23, 2009 would % 1 == 0 be a good check for a whole number? and is there a method for checking is a number? regards Link to comment https://forums.phpfreaks.com/topic/182612-check-for-is-a-whole-number-and-is-aa-number/ Share on other sites More sharing options...
monkeytooth Posted November 23, 2009 Share Posted November 23, 2009 is_numeric would be a method to check if a string is a number. but what do you mean exactly by whole number? Link to comment https://forums.phpfreaks.com/topic/182612-check-for-is-a-whole-number-and-is-aa-number/#findComment-963815 Share on other sites More sharing options...
Mchl Posted November 23, 2009 Share Posted November 23, 2009 is_int Link to comment https://forums.phpfreaks.com/topic/182612-check-for-is-a-whole-number-and-is-aa-number/#findComment-963816 Share on other sites More sharing options...
Daniel0 Posted November 23, 2009 Share Posted November 23, 2009 would % 1 == 0 be a good check for a whole number? No. In fact it won't work. 1.5 % 1 == 0 is true because 1.5 is implicitly casted to int. $n % 1 == 0 is a tautology in PHP even for floating point numbers. but what do you mean exactly by whole number? A whole number is an integer, i.e. a number without a fractional part. Link to comment https://forums.phpfreaks.com/topic/182612-check-for-is-a-whole-number-and-is-aa-number/#findComment-963817 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.