detecting negative numbers
detecting negative numbers
am 16.07.2006 17:37:20 von Dave W
------=_Part_77003_28034286.1153064240154
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Currently I have this:
if($quant > $amount) {echo "You don't have that many!"; }
$quant is the user inputted amount and $amount is the amount that they
actually have. Is there any way of checking if the result is negative rather
than doing what I have above?
--
Dave W
------=_Part_77003_28034286.1153064240154--
Re: detecting negative numbers
am 16.07.2006 19:45:07 von Peter Beckman
On Sun, 16 Jul 2006, Dave W wrote:
> Currently I have this:
>
> if($quant > $amount) {echo "You don't have that many!"; }
>
> $quant is the user inputted amount and $amount is the amount that they
> actually have. Is there any way of checking if the result is negative rather
> than doing what I have above?
I'm not sure which "result" you are refering to, but this echo's if:
$quant is greater than $amount
$amount is less than 0
$quant is less than 0
if ($quant > $amount or $amount < 0 or $quant < 0) {
echo "You don't have that many!";
}
------------------------------------------------------------ ---------------
Peter Beckman Internet Guy
beckman@purplecow.com http://www.purplecow.com/
------------------------------------------------------------ ---------------
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: detecting negative numbers
am 16.07.2006 21:35:57 von Dave W
------=_Part_79636_6486386.1153078557487
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
They are both positive numbers. I want to see if, when subtract, do they
equal a negative number?
On 7/16/06, Peter Beckman wrote:
>
> On Sun, 16 Jul 2006, Dave W wrote:
>
> > Currently I have this:
> >
> > if($quant > $amount) {echo "You don't have that many!"; }
> >
> > $quant is the user inputted amount and $amount is the amount that they
> > actually have. Is there any way of checking if the result is negative
> rather
> > than doing what I have above?
>
> I'm not sure which "result" you are refering to, but this echo's if:
> $quant is greater than $amount
> $amount is less than 0
> $quant is less than 0
>
> if ($quant > $amount or $amount < 0 or $quant < 0) {
> echo "You don't have that many!";
> }
>
>
> ------------------------------------------------------------ ---------------
> Peter Beckman Internet
> Guy
> beckman@purplecow.com
> http://www.purplecow.com/
>
> ------------------------------------------------------------ ---------------
>
--
Dave W
------=_Part_79636_6486386.1153078557487--
Re: detecting negative numbers
am 17.07.2006 01:05:23 von Stut
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dave W wrote:
> Currently I have this:
>
> if($quant > $amount) {echo "You don't have that many!"; }
>
> $quant is the user inputted amount and $amount is the amount that they
> actually have. Is there any way of checking if the result is negative
> rather
> than doing what I have above?
Not sure which way around you want it, but I think this is what you are
after...
if (($quant - $amount) < 0)
{
echo "You don't have that many!";
}
I don't mean any offense, but the possibility that someone who couldn't
figure that out is writing PHP code scares me. You might want to think
about Googling for an absolute beginners guide to programming before
continuing.
- -Stut
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFEusYz2WdB7L+YMm4RAqGPAJ0QqkgfApO6h0GR9lXa47WyAhSsugCf aymW
Ba+bqZRbrcv6CuZ6g7FJJjw=
=ktnc
-----END PGP SIGNATURE-----
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: detecting negative numbers
am 17.07.2006 02:06:41 von Dave W
------=_Part_82314_18361842.1153094801856
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
No, I get it. I just thought that there might have been some built in
function like if(neg_num($quant - $amount))
or something like that. I know how to do it, but I thought that there might
have been an alternate method. Just because I asked a simple question
doesn't mean I'm stupid, I'm just curious if there is a simpler way to do an
already simple task.
On 7/16/06, Stut wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Dave W wrote:
> > Currently I have this:
> >
> > if($quant > $amount) {echo "You don't have that many!"; }
> >
> > $quant is the user inputted amount and $amount is the amount that they
> > actually have. Is there any way of checking if the result is negative
> > rather
> > than doing what I have above?
>
> Not sure which way around you want it, but I think this is what you are
> after...
>
> if (($quant - $amount) < 0)
> {
> echo "You don't have that many!";
> }
>
> I don't mean any offense, but the possibility that someone who couldn't
> figure that out is writing PHP code scares me. You might want to think
> about Googling for an absolute beginners guide to programming before
> continuing.
>
> - -Stut
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2.2 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFEusYz2WdB7L+YMm4RAqGPAJ0QqkgfApO6h0GR9lXa47WyAhSsugCf aymW
> Ba+bqZRbrcv6CuZ6g7FJJjw=
> =ktnc
> -----END PGP SIGNATURE-----
>
--
Dave W
------=_Part_82314_18361842.1153094801856--
RE: detecting negative numbers
am 17.07.2006 10:39:51 von M.Ford
On 17 July 2006 01:07, Dave W wrote:
> No, I get it. I just thought that there might have been some built in
> function like if(neg_num($quant - $amount))
> or something like that. I know how to do it, but I thought
> that there might
> have been an alternate method. Just because I asked a simple question
> doesn't mean I'm stupid, I'm just curious if there is a
> simpler way to do an
> already simple task.
The absolute simplest way to do this is what you originally had. I would n=
ot look further than
if ($quant<$amount)
// $quant-$amount is negative
If I were reading your code, I would find both if(($quant-$amount)<0) and i=
f(neg_num($quant-$amount)) more obfuscating than if($quant<$amount).
Cheers!
Mike
------------------------------------------------------------ ---------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211=20
To view the terms under which this email is distributed, please go to http:=
//disclaimer.leedsmet.ac.uk/email.htm
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: detecting negative numbers
am 17.07.2006 14:51:56 von John in Pueblo
Dave W wrote:
> No, I get it. I just thought that there might have been some built in
> function like if(neg_num($quant - $amount))
> or something like that. I know how to do it, but I thought that there
> might
> have been an alternate method. Just because I asked a simple question
> doesn't mean I'm stupid, I'm just curious if there is a simpler way to
> do an
> already simple task.
I think this is a case of trying to out-think yourself.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php