-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
I came upon an alogrithm years ago somewhere that showed how to programmatically round
numbers. Here
it is:
// num is the number we want to round. it may be int or fp.
// what is what we want to round num to (ie nearest 10, 1/100, etc)
// The rounding
Hi
I seem to be having problems returning the expected results when using
the mysql ROUND() function.
Rounding 3.565 to 2 decimal places i would expect to return 3.57
however using
SELECT ROUND(3.565, 2);
it returns 3.56. While using
SELECT ROUND(3.575, 2);
works as expected returning 3.58.
I
[mailto:[EMAIL PROTECTED]
Verzonden: maandag 25 oktober 2004 19:35
Aan: [EMAIL PROTECTED]
Onderwerp: rounding problem
Hi
I seem to be having problems returning the expected results when using
the mysql ROUND() function.
Rounding 3.565 to 2 decimal places i would expect to return 3.57
however
/myodbc/8
Regards,
Edgar
-Oorspronkelijk bericht-
Van: Tom Butterworth [mailto:[EMAIL PROTECTED]
Verzonden: maandag 25 oktober 2004 19:35
Aan: [EMAIL PROTECTED]
Onderwerp: rounding problem
Hi
I seem to be having problems returning the expected results when using
the mysql ROUND() function
[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