| BEWARE! Earthborn's function looked nice until I tested it >>>November 7 2007 at 6:21 PM | Moneo (no login) |
Response to Very nice! But could be shortened though... |
| The following is Earthborn's original function:
FUNCTION Round (Num, Decimals)
n = Num * (10 ^ Decimals)
n = SGN(n) * (ABS(INT(n + .5)))
Round = n / (10 ^ Decimals)
END FUNCTION
The error lies in this statement:
n = SGN(n) * (ABS(INT(n + .5)))
The intent of the ABS is to feed an absolute value to the INT, because INT works differently for negative numbers.
The corrected function follows:
FUNCTION Round (Num, Decimals)
n = Num * (10 ^ Decimals)
R = SGN(N)*INT(ABS(N)+.5) '*** FIXED ***
Round = n / (10 ^ Decimals)
END FUNCTION
NOTE: Earthborn's function did not declare the rounding method used. It is Symmetric Arithmetic Rounding, the most commonly used method.
Regards..... Moneo
|
| | Responses |
|
|