Link to home
Start Free TrialLog in
Avatar of jagguy
jagguyFlag for Australia

asked on

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

Avatar of Sethi
Sethi
Flag of India image

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
Avatar of brandonvmoore
brandonvmoore

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.
ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Another way:
        Dim number As Decimal = 6.8
 
        If number - Decimal.Truncate(number) <> 0 Then
            Stop ' Fractional number 
        End If

Open in new window