# is integer

how do i detect if a number has no floating point  in vb.net

i want to distinguish between  say 6 and 6.8

###### Who is Participating?

Commented:
anther way

if val(mynumber) <> int(mynumber) then
msgbox "decimal"

val will return number you pass in eg. val(5.2) returns 5.2
int returns whole part, not decimal eg int(5.2) returns 5
0

Commented:
You can finding a decimal in a number by using IndexOf function like this:
Dim strvalue As String = "6.8"
If strvalue.IndexOf(".") >=0 then
Messagebox.show "It's a decimal value"
end if
0

Commented:
There may be a function just for doing that, but here's the solution that comes to mind first:

Dim l as long = 5.6
if l - CInt(l) = 0 then msgbox("l is an integer") else msgbox("l is not an integer")

In other words, cast it to an integer and subtract that from the original value to see if there is anything left over.
0

IT Pro/DeveloperCommented:
Another way:
``````        Dim number As Decimal = 6.8

If number - Decimal.Truncate(number) <> 0 Then
Stop ' Fractional number
End If
``````
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.