Re: Number question

From: Craig Keightley (dont_at_spam.me)
Date: 09/24/04


Date: Fri, 24 Sep 2004 16:42:38 +0100

Thanks all but i went with this:
$round_x = 5 * ceil($x/5);

"Ehtor" <nomail@nomail.com> wrote in message
news:Xns956E75DFD247Fnomailnomailcom@140.99.99.130...
> Or as a function:
>
> function another_round5($x)
> {
> if( !($x % 5) )
> return($x);
> else
> return((intval($x/5)+1)*5);
> }
>
>
>
> Ehtor <nomail@nomail.com> wrote in
> news:Xns956E750BD82C5nomailnomailcom@140.99.99.130:
>
>> Try this sample:
>>
>> for($x=0;$x<30;$x++)
>> {
>> if( !($x % 5) ) // if mod is zero, we're already there
>> {
>> $nearest = $x;
>> }
>> else
>> {
>> $nearest = (intval($x/5)+1)*5;
>> }
>>
>> echo "\n $x rounds to $nearest";
>> }
>>
>>
>>
>> "Craig Keightley" <dont@spam.me> wrote in
>> news:41542f09$0$20250$cc9e4d1f@news-text.dial.pipex.com:
>>
>>> Is there a way to "round" (bad use of the word) a number to the
>>> nearest 5 eg
>>> 4 => 5
>>> 7 => 10
>>> 1 => 5
>>> 12 => 15
>>>
>>> Many Thanks for any help provide
>>> Craig
>>>
>>>
>>>
>>
>>
>