Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining of a double has a decimal

Status
Not open for further replies.

pterochild

Programmer
Apr 18, 2002
8
CA
Hi all,

I am wondering how to determine of a double X has a decimal or not.

For example:
5.2 would have a decimal
5.0 would not
5.000009 would

Anyone??
 
Here you go:

Code:
If Int (dblX) = dblX Then
 ' number does not have decimal place
Else
 ' number does have
End If

John
 
Have you tried something like this ?
If CDbl(Clng(myDouble)) = myDouble

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Store your double into an integer, than back into a double. If the two doubles match, there is no decimal.

Double numA, numB
Integer numInt

numA = someNumber
numInt = numA
numB = numInt

If(numA=numB) Then
'No decimal
Else
'Some decimal
End if
 
jrbarnetts does the same thing, just mine describes what is going on behind the scenes. Typecasting as he does is faster and does the same thing.
 
I would suggest that you not cast to Integer, but rather cast to Long. You're much less likely to encounter an Overflow Error by using Long.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Depending on how you intend to use, I would be wary of moving a floating point number like the double to an integer number and then making a comparison.

Dim theDate1 As Double, theDate2 As Double
Dim theLong As Long

theDate1 = 5999999.9999
theDate2 = 5999999
'- strip the decimal.
theLong = theDate1
theDate1 = theLong

'- Would you guess that the two number would remain the same and both have no decimal.

Debug.Print theDate1; " "; theDate2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top