Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

is integer

Posted on 2009-04-09
4
Medium Priority
?
294 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

926 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