jagguy
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
i want to distinguish between say 6 and 6.8
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Another way:
Dim number As Decimal = 6.8
If number - Decimal.Truncate(number) <> 0 Then
Stop ' Fractional number
End If
Dim strvalue As String = "6.8"
If strvalue.IndexOf(".") >=0 then
Messagebox.show "It's a decimal value"
end if