Default code

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
phpnoobyyy
Forum Newbie
Posts: 14
Joined: Mon Oct 12, 2009 3:27 pm

Default code

Post 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
davegmpd
Forum Newbie
Posts: 14
Joined: Tue Oct 27, 2009 9:42 am
Location: London

Re: Default code

Post 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
phpnoobyyy
Forum Newbie
Posts: 14
Joined: Mon Oct 12, 2009 3:27 pm

Re: Default code

Post 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
Post Reply