I'd like to know what is the best way to check whether a numeric string is positive or negative.
I am using this answer on S.O but I am not able to determine whether a number with decimals is + or -
For example :
function check_numb($Degree){
if ( (int)$Degree == $Degree && (int)$Degree > 0 ) {
return 'Positive';
} else {
return 'Negative';
}
}
print check_numb("+2"); // returns Positive
print check_numb("+2.0"); // returns Positive
print check_numb("+2.1"); // returns Negative ??
print check_numb("+0.1"); // returns Negative ??
print check_numb("-0.1"); // returns Negative
It seems when a decimal is added it returns false. How do you properly check for positive strings > +0.XX
and negative < -0.XX
which 2 decimals..
Thanks!