Test for fractions of a penny
Eric,
How about multiplying the test value by 100, subtract the integer portion
and test whats left against zero.
eg: 100.47 x 100 = 10047
10047 -int(10047) = 0 ' the value is ok
100.472 x 100 = 10047.2
10047.2 - int(10047.2) = .2 ' user enter a fraction of a cent
Roy
"Wescotte" wrote:
I'm attempting to write code to determine if the user entered a value
that has a fraction of a cent. Here is my logic
dim i as long
dim d as double
If IsNumeric(.Value) = True And .Value < 0 Then
.Value = Abs(.Value)
i = CLng(CDbl(.Value) * 100)
d = CDbl(.Value) * 100
If Abs(d - i) 0 Then
MsgBox "Rounding error detected! Make sure you don't have umbers
with values less than 1/100th", vbExclamation
End If
Else
.Value = ""
End If
It seems to work for most cases however I'd found some specific values
that always report "Round error detected!...."
Values such as 282.47, 32.41 and 132.70
If I MsgBox i & " " & d the numbers are the same so
Abs(d - i) 0 should always be false I don't quite understand what's
doing on. Is there a better way to test for fractions of a cent?
Eric
|