what i want to do is round up to the nearest even number example so if someone puts in 10.25 i want to to go up to 12 if ( ($totalwidth % 2) != 0 ) { $totalwidth = $totalwidth + 1; } PHP: i was also given if (totalwidth % 2) { var totalwidth = ++totalwidth; } PHP: but that was for java and didn't work in php thank you for your time phil.
That won't work for 10.25. PHP returns 10.25 as being equal to 0, if you use 11.25, it will add 1 but will display 12.25. The code below works to make 10.25 return 12 : $totalwidth = 10.25; $totalwidth = ceil($totalwidth); echo "$totalwidth <br> "; if ( ($totalwidth % 2) != 0 ) { $totalwidth = $totalwidth + 1; } echo "$totalwidth <br> "; Code (markup):
wow! i didn't even know that ceil() existed! thanks again I appreciate the help. I have a quick question for you do you knokw of any good places to learn php? other then bothering people on the forums? thanks again shallowink!
The usual places, w3schools.com, tizag.com, php-mysql-tutorial.com and php.net for reference. Lots of stuff on all of those, the tizag.com is good but its kind of dated. But those are probably the best. Once you get a good idea of the terminology google searches turn up answers faster than anything else. And bugging people on the forums is fine, just be sure to show some effort/code and most times its fine. Good Luck.
http://www.w3schools.com/php/php_ref_math.asp The main thing is knowing what to look for. In your case you were looking for math functions. So you pop "php math functions" into Google and you get that url as the first result. That page gives you every PHP math function and what it does. You want to be familiar with those in any language.