Re: Math rounding problem
| From: | DL Neil | Date: | Sat, 09 Feb 2002 00:32:25 +0000 |
| Subject: | Re: Math rounding problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-84071@lists.php.net to get a copy of this message | ||
Charlie,
> For an arbitrary large number I need to round() it up to the hundreds place
> if it is not divisible by 100 and leave it untouched if it is.
>
> So 1100 would round to 1100 and
> 1101 would round to 1200.
>
> Is there a clean way to do this?
>
> Currently I'm:
> $scale = round($scale+49, -2); // round up to hundreds.
>
> But this is messy.
You thought that was messy? Try:
if ( ( intval( $scale / 100 ) * 100 ) < $scale )
{
$scale = 1 + ( intval( $scale / 100 ) * 100 );
}
Regards,
=dn