Solved

is integer

Posted on 2009-04-09
4
250 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
ID: 24113474
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
ID: 24113478
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
ID: 24113737
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
ID: 24114120
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

832 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