SOLVED! Can't get code to check for POSITIVE float vals

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ShadowIce
Forum Commoner
Posts: 75
Joined: Tue Jan 12, 2010 8:43 am

SOLVED! Can't get code to check for POSITIVE float vals

Post 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';
      }
Last edited by ShadowIce on Wed Jan 20, 2010 12:15 pm, edited 1 time in total.
ShadowIce
Forum Commoner
Posts: 75
Joined: Tue Jan 12, 2010 8:43 am

Re: PLEASE HELP! Can't get code to check for POSITIVE float vals

Post by ShadowIce »

this code only checks for negative floats, and numbers <= 0....
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PLEASE HELP! Can't get code to check for POSITIVE float vals

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PLEASE HELP! Can't get code to check for POSITIVE float vals

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
ShadowIce
Forum Commoner
Posts: 75
Joined: Tue Jan 12, 2010 8:43 am

Re: PLEASE HELP! Can't get code to check for POSITIVE float vals

Post by ShadowIce »

That's ok man. I fixed THAT part. I made a NEWER post w/ the last REAL problem im having :)
Post Reply