Re: Rounding down?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I also wrote a function for that,

function round_to($number, $increments) {
$increments = 1 / $increments;
return (round($number * $increments) / $increments);
}

(Also published on php manual - round() )


On Sat, Aug 22, 2009 at 4:11 PM, Ron Piggott <ron.php@xxxxxxxxxxxxxxxxxx>wrote:

> Thanks; Amazing.  Ron
>
> ----- Original Message ----- From: "Ashley Sheridan" <
> ash@xxxxxxxxxxxxxxxxxxxx>
> To: "Richard Heyes" <richard@xxxxxxx>
> Cc: "Ron Piggott" <ron.php@xxxxxxxxxxxxxxxxxx>; <php-general@xxxxxxxxxxxxx
> >
> Sent: Saturday, August 22, 2009 9:02 AM
> Subject: Re:  Rounding down?
>
>
>  On Sat, 2009-08-22 at 13:00 +0100, Richard Heyes wrote:
>>
>>> Hi,
>>>
>>> > Is there a way to round down to the nearest 50?
>>> >
>>> > Example: Any number between 400 and 449 I would 400 to be displayed; >
>>> 450 to 499 would be 450; 500 to 549 would be 500, etc?
>>>
>>> Off the top of my head: divide the number by 50, run floor() on the
>>> result, then times it by 50.
>>>
>>> 1. 449 / 50 = 9.whatever
>>> 2. floor(9.whatever) = 9
>>> 3. 9 * 50 = 450
>>>
>>> --
>>> Richard Heyes
>>> HTML5 graphing: RGraph - www.rgraph.net (updated 8th August)
>>> Lots of PHP and Javascript code - http://www.phpguru.org
>>>
>>>
>> It should be round() and not floor().
>>
>> 449 / 50 = 8.98
>> floor(8.98) = 8
>> 8 * 50 = 400
>>
>> round(8.98) = 9
>> 9 * 50 = 450
>>
>>
>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>>
>>
>>
>>
>
>
> --------------------------------------------------------------------------------
>
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.5.409 / Virus Database: 270.13.64/2319 - Release Date: 08/22/09
> 06:06:00
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Use ROT26 for best security

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux