Solved

# is integer

Posted on 2009-04-09
232 Views
how do i detect if a number has no floating point  in vb.net

i want to distinguish between  say 6 and 6.8

0
Question by:jagguy

LVL 18

Expert Comment

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

LVL 5

Expert Comment

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

LVL 65

Accepted Solution

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

LVL 48

Expert Comment

Another way:
``````        Dim number As Decimal = 6.8

If number - Decimal.Truncate(number) <> 0 Then

Stop ' Fractional number

End If
``````
0

## Featured Post

### Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …