Re: [PHP] Here's my rounding

2012-09-29 Thread Tedd Sperling
On Sep 28, 2012, at 9:27 AM, Jim Giner  wrote:

> On 9/28/2012 2:11 AM, Simon J Welsh wrote:
>> On 28/09/2012, at 6:08 PM, Chris Payne  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

_
t...@sperling.com
http://sperling.com


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



Re: [PHP] Here's my rounding

2012-09-28 Thread Jim Giner

On 9/28/2012 2:11 AM, Simon J Welsh wrote:

On 28/09/2012, at 6:08 PM, Chris Payne  wrote:


$test2 = '253177';
echo $tes2 . " rounded to: ";
$rounded_number = round($test2,-3);
echo $rounded_number;

Is it SUPPOSED to happy a number is sent to this little system and it's
SUPPOSED to round the number up.  So if the number was 144035 the system
should look at it and say "Hey uo,
we need to round this up"  So basicially I need it to convert in
thousands.  Even if the total is a fraction over it still needs to ne
calculated as the next thousand up.

Sprru of o'm confusing you, i'm very tired.  So basically, just make the
last 4 numbers always round up.  255000 would be correct - 255590 would
beINSORERECT as it should display 255600.

Hope that helped someone to help me :-)

xxx
Chris



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... :)


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



Re: [PHP] Here's my rounding

2012-09-27 Thread Simon J Welsh
On 28/09/2012, at 6:08 PM, Chris Payne  wrote:

> $test2 = '253177';
> echo $tes2 . " rounded to: ";
> $rounded_number = round($test2,-3);
> echo $rounded_number;
> 
> Is it SUPPOSED to happy a number is sent to this little system and it's
> SUPPOSED to round the number up.  So if the number was 144035 the system
> should look at it and say "Hey uo,
> we need to round this up"  So basicially I need it to convert in
> thousands.  Even if the total is a fraction over it still needs to ne
> calculated as the next thousand up.
> 
> Sprru of o'm confusing you, i'm very tired.  So basically, just make the
> last 4 numbers always round up.  255000 would be correct - 255590 would
> beINSORERECT as it should display 255600.
> 
> Hope that helped someone to help me :-)
> 
> xxx
> Chris


I would use something similar to $rounded_number = ceil($test2/1000)*1000;
---
Simon Welsh
Admin of http://simon.geek.nz/


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