Page 1 of 1

Rounding negative

Posted: Fri Aug 06, 2010 3:01 pm
by spacebiscuit
Hi guys,

I'm not sure if such a functio exists - but is it possible to have a number rounded up to 0 if and only if it is negative?

Thanks in advance,

Rob.

Re: Rounding negative

Posted: Fri Aug 06, 2010 3:08 pm
by PHPHorizons
Whereas, if the number were positive, it would just leave the number unchanged? I don't believe so.

Re: Rounding negative

Posted: Fri Aug 06, 2010 3:53 pm
by ColonelSandersLite
Simple:

Code: Select all

if ($number < 0) {$number = 0;};
You could even make a custom function to do it if you so pleased, though it may not be worth the effort, because this isn't something you'll need to do a lot really.

Re: Rounding negative

Posted: Fri Aug 06, 2010 7:29 pm
by Weirdan

Code: Select all

$number = max($number, 0);