GentleGeek
New Member
- Joined
- May 31, 2009
- Messages
- 8
Hello, New to the Forum. Looks great!!
I am pulling out my hair at the moment-
I have learned that the ROUND function functions differently in VBA vs. in a worksheet.
I have found an MS webpage that explains and also gives some alternate functions that "should" solve the problem.
http://support.microsoft.com/kb/196652
But, my problem remains. There may be a "bug" in the "Fix" Function.
The "bug" (which I have traced in excruciating detail in the VBA) is when I want to round "9.405" to 2 decimals for example, the SymArith function gets a correct intermediate value of "941", but FIX() then gives me "940", and my final result comes out to "9.40". What gives? This is not a "fix"!!
Here is MS's code:
(One note about this function and the other replacement functions, MS should have used "10^Factor" instead of just "Factor", so that the functions would work the same as the regular ROUND function.
To debug, I broke the calculation into 2 steps, used Breakpoints to check intermediate values, and used "10^Factor" instead of just "Factor". I still get the same wrong result:
HELLLLLLLPPPP!!!!
Thanks in advance.
I am pulling out my hair at the moment-
I have learned that the ROUND function functions differently in VBA vs. in a worksheet.
I have found an MS webpage that explains and also gives some alternate functions that "should" solve the problem.
http://support.microsoft.com/kb/196652
But, my problem remains. There may be a "bug" in the "Fix" Function.
The "bug" (which I have traced in excruciating detail in the VBA) is when I want to round "9.405" to 2 decimals for example, the SymArith function gets a correct intermediate value of "941", but FIX() then gives me "940", and my final result comes out to "9.40". What gives? This is not a "fix"!!
Here is MS's code:
Code:
Function SymArith(ByVal X As Double, _
Optional ByVal Factor As Double = 1) As Double
SymArith = Fix(X * Factor + 0.5 * Sgn(X)) / Factor
End Function
To debug, I broke the calculation into 2 steps, used Breakpoints to check intermediate values, and used "10^Factor" instead of just "Factor". I still get the same wrong result:
Code:
Function RoundSymArith(ByVal X As Double, _
Optional ByVal Factor As Double = 1) As Double
Dim XX As Double
XX = X * 10 ^ Factor + 0.5 * Sgn(X)
RoundSymArith = Fix(XX) / 10 ^ Factor
End Function
Thanks in advance.