Solved

is integer

Posted on 2009-04-09
4
232 Views
Last Modified: 2012-05-06
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
Comment
Question by:jagguy
4 Comments
 
LVL 18

Expert Comment

by:Sethi
Comment Utility
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

by:brandonvmoore
Comment Utility
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

by:
rockiroads earned 500 total points
Comment Utility
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

by:jpaulino
Comment Utility
Another way:
        Dim number As Decimal = 6.8
 

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

            Stop ' Fractional number 

        End If

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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: …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now