This is floating point computation issue (i think).
This is 2 round function i found somewhere.
They look very similar in code but when i run it, i get 2 different result.
In this example when run this code with value is 87.13225 and precision 4 :
a = 87.1322
b = 87.1323
Anyone can explain what happen?
Private Sub Form_Load()
Dim a#
Dim b#
a = Round1(87.13225, 4) '87.1322
b = Round2(87.13225, 4) '87.1323
End Sub
Private Function Round1(ByVal value#, ByVal vPrecision%)
Round1 = Fix((value + Sgn(value) / 10 ^ vPrecision / 2) * _
10 ^ vPrecision) _
/ 10 ^ vPrecision
End Function
Private Function Round2(ByVal value#, ByVal vPrecision%)
Dim a#
a = (value + Sgn(value) / 10 ^ vPrecision / 2) * 10 ^ vPrecision
Round2 = Fix(a) / 10 ^ vPrecision
End Function