Juggler_IN
Active Member
- Joined
- Nov 19, 2014
- Messages
- 349
- Office Version
- 2003 or older
- Platform
- Windows
The following RoundtoUp code is failing in few specific cases as compared with Excel RoundUp:
<tbody>
</tbody>
Could not debug the reason for such a behavior. What is a possible fix?
Code:
Public Function RoundtoUp( _
ByVal myNum As Double, _
Optional ByVal myFac As Double = 1#) As Double
RoundtoUp = (Fix(myNum * CDec(10# ^ myFac)) + IIf(myNum = Fix(myNum * CDec(10# ^ myFac)), 0, Sgn(myNum))) / CDec(10# ^ myFac)
End Function
Number | Digits | RoundtoUp | RoundUp (Excel) | |
0.0099, | 1 | Ok | '0.1 | '0.1 |
0.0099, | 2 | Ok | '0.01 | '0.01 |
0.0099, | 3 | Ok | '0.01 | '0.01 |
0.0099, | 4 | Error | '0.01 | '0.0099 |
-0.0714285714, | 2 | Ok | '-0.08 | '-0.08 |
-1.2345, | 3 | Ok | '-1.235 | '-1.235 |
1.01234012340125, | 14 | Error | '1.01234012340126 | '1.01234012340125 |
<tbody>
</tbody>
Could not debug the reason for such a behavior. What is a possible fix?
Last edited: