Solved

is integer

Posted on 2009-04-09
4
269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

635 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