is integer

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

i want to distinguish between  say 6 and 6.8

Who is Participating?
rockiroadsConnect With a Mentor 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
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 "It's a decimal value"
end if
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.
Jorge PaulinoIT Pro/DeveloperCommented:
Another way:
        Dim number As Decimal = 6.8
        If number - Decimal.Truncate(number) <> 0 Then
            Stop ' Fractional number 
        End If

Open in new window

All Courses

From novice to tech pro — start learning today.