Page 1 of 1

Default code

Posted: Thu Oct 29, 2009 2:12 pm
by phpnoobyyy
Hi guys

I have a bit of code that defines a default figure if a calculation equals or is less than a certain figure. It works fine in this sens. However, the problem I'm having is that when the calculated figure is greater than 9999 (e.g. 99999) the figure defaults to the default figure. This is unintended and the code as written offers no explanation to me as to why it is doing this.

I was wandering therefore if someone could have a look at it and see what, if anything, is making it do this. Here's the code (it's a pretty simple code).

Code: Select all

$defprice = 50;
if ($price <=0) {
$price =0;
}
elseif ($price < $defprice) {
$price =$defprice;
}
All and any help greatly appreciated.

Thanks

Re: Default code

Posted: Fri Oct 30, 2009 12:08 pm
by davegmpd
Your code snippet wouldn't have the problem you describe. It must be something you've *not* posted. I guess that doesn't help you too much ;)

Dave

Re: Default code

Posted: Fri Oct 30, 2009 3:18 pm
by phpnoobyyy
Hi all

problem solved.

I cornered it down to the placement of the following code (which I didn't provide in my initial post) within my script:

Code: Select all

$price = number_format($price, 2);
I've moved this code and placed it elsewhere within the script and the function seems to be working as intended.

Thanks