Page 1 of 1
Stopping at "zero".
Posted: Thu Apr 05, 2007 9:28 pm
by Mightywayne
So I've got this script. Takes the info from the database fine, and now I've got to substract things.. err, example.
Code: Select all
$value1 = 5
$value2 = 9
$value3 = $value1 - $value2
So what happens is, the script will actually make it go into -4. >_> But I need it to stop at zero. I'm sure/hoping it's a simple answer.
Posted: Thu Apr 05, 2007 9:29 pm
by Begby
Is this in a loop of some sort? If so please post your code with the loop logic, or a sample loop.
Posted: Thu Apr 05, 2007 9:30 pm
by Mightywayne
Argh, you posted just as I found it. >_>; Oh boy.
abs()
I'm pretty sure that's it. I didn't go to my math class this year (long story) so I've pretty much forgotten absolute numbers turn negatives to positives. let's see if it works.
Edit: No. I suck at math. ... It just returned a positive number that wasn't zero.
And well yes, this IS a loop... but uhm. It's quite long and it's really not that important, because I tried it on its own and I still get the error.
Posted: Thu Apr 05, 2007 9:33 pm
by Benjamin
Code: Select all
$value3 = ($value3 < 0) ? 0 : $value3;
Posted: Thu Apr 05, 2007 9:36 pm
by Mightywayne
Aha! It's stupid small posts like these that make me wonder if I should just delete the topic.
But I suppose it'd be frowned upon because of not helping or something.
REGARDLESS! Thank you gentlemen both. I didn't even know of the ? thing.
Posted: Thu Apr 05, 2007 11:13 pm
by feyd