View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
okaizawa okaizawa is offline
external usenet poster
 
Posts: 129
Default Test for fractions of a penny

Hi,
how about this:

If CStr(CLng(.Value * 100) / 100) < CStr(.Value) Then

--
HTH
okaizawa


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