Re: Here's my rounding

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

 



On Sep 28, 2012, at 9:27 AM, Jim Giner <jim.giner@xxxxxxxxxxxxxxxxxx> wrote:

> On 9/28/2012 2:11 AM, Simon J Welsh wrote:
>> On 28/09/2012, at 6:08 PM, Chris Payne <oxygenet32@xxxxxxxxx> wrote:
>> 
>> I would use something similar to $rounded_number = ceil($test2/1000)*1000;
>> ---
>> Simon Welsh
>> Admin of http://simon.geek.nz/
>> 
> From my days as a math major, rounding doesn't always go up - it goes to the nearest level that you have indicated.  As Simon shows you, you want to ceil to always go up, and floor to always go down.  Neat function names actually... :)

A more accurate rounding is HALF-EVEN -- first Google search produces:

http://www.crazysquirrel.com/computing/java/basics/rounding.jspx

I did this with php several years ago, namely:

http://www.webbytedd.com/bbb/rounding/

I leave it to the community to develop the code.

Cheers,

tedd

_____________________
tedd@xxxxxxxxxxxx
http://sperling.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[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