Page 1 of 1
SOLVED! Can't get code to check for POSITIVE float vals
Posted: Wed Jan 20, 2010 7:32 am
by ShadowIce
How can I get this code to check for positive AND negative floats? NOT just negative floats?
Code: Select all
if (!is_numeric($values['qtycd_0001']) || $values['qtycd_0001'] <= 0 || is_float($values['qtycd_0001'])) {
$errors['qtycd_0001'] = ' * '.$values['qtycd_0001'].' is an invalid amount';
}
Re: PLEASE HELP! Can't get code to check for POSITIVE float vals
Posted: Wed Jan 20, 2010 7:33 am
by ShadowIce
this code only checks for negative floats, and numbers <= 0....
Re: PLEASE HELP! Can't get code to check for POSITIVE float vals
Posted: Wed Jan 20, 2010 9:56 am
by pickle
If 0 is acceptable as well, then all positive floats, all negative floats, and 0 consist of the entire range of floats. Just check if the value is a float and leave it at that.
Re: PLEASE HELP! Can't get code to check for POSITIVE float vals
Posted: Wed Jan 20, 2010 10:33 am
by AbraCadaver
Not sure what you're doing. Just a guess that these are coming from a database or from a post operation? If so, they will always be a string and is_float() will always return false.
Re: PLEASE HELP! Can't get code to check for POSITIVE float vals
Posted: Wed Jan 20, 2010 12:15 pm
by ShadowIce
That's ok man. I fixed THAT part. I made a NEWER post w/ the last REAL problem im having
