[ob. filter faker: mysql]

For what it's worth, here's an algorithm I use to write my own rounding
function.

To round to the nearest N number of places.

1) divide the number by N
2) add .5 (for negative numbers subtract .5)
3) truncate the result (take integer part)
4) multiply result by N

Example: To round 758.43 to nearest 10's
1) 758.43 / 10 = 75.843
2) 75.843 + .5 = 76.343
3) int(76.343) = 76
4) 76 * 10 = 760

Example: To round 758.437 to nearest 1/100th
1) 758.437 / 1/100 = 75843.7
2) 75843.7 + .5 = 75844.2
3) int(75844.2) = 75844
4) 75844 * 1/100 = 758.44

Example: To round -758.437 to nearest 1/100th
1) -758.437 / 1/100 = -75843.7
2) -75843.7 - .5 = -75844.2
3) int(-75844.2) = -75844
4) -75844 * 1/100 = -758.44
-- 
Amer Neely [EMAIL PROTECTED]
Softouch Information Services: www.softouch.on.ca/
Perl / PHP / CGI programming for shopping carts, data entry forms.
"We make web sites work!"

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to