473,382 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

how to determine if numeric data contains a decimal?

Is there a way to determine if a numeric value contains a decimal? how to do
this?

If IsNumeric(txt1.Text) then ... so now I know that txt1.Text is a numeric
value. How can I tell if it is a plain integer or decimal?

Thanks,
Rich
Feb 20 '07 #1
4 14900
On Feb 20, 1:55 pm, Rich <R...@discussions.microsoft.comwrote:
Is there a way to determine if a numeric value contains a decimal? how to do
this?

If IsNumeric(txt1.Text) then ... so now I know that txt1.Text is a numeric
value. How can I tell if it is a plain integer or decimal?

Thanks,
Rich
Parse the string for a period using IndexOf.

<pseudocode>

if IsNumeric(txt1.Text) then
if txt1.IndexOf(".") <-1 then
' Decimal
else
' Integer
end if
end if

</pseudocode>

Thanks,

Seth Rowe

Feb 20 '07 #2
rowe_newsgroups wrote:
On Feb 20, 1:55 pm, Rich <R...@discussions.microsoft.comwrote:
>Is there a way to determine if a numeric value contains a decimal? how to do
this?

If IsNumeric(txt1.Text) then ... so now I know that txt1.Text is a numeric
value. How can I tell if it is a plain integer or decimal?

Thanks,
Rich

Parse the string for a period using IndexOf.

<pseudocode>

if IsNumeric(txt1.Text) then
if txt1.IndexOf(".") <-1 then
' Decimal
else
' Integer
end if
end if

</pseudocode>

Thanks,

Seth Rowe
That's assuming that the decimal separator is a period, which it isn't
everywhere.

The decimal separator for any given culture can be found in the
NumberFormat.NumberDecimalSeparator property.

--
Göran Andersson
_____
http://www.guffa.com
Feb 20 '07 #3
"Göran Andersson" <gu***@guffa.comwrote in message
news:Og**************@TK2MSFTNGP06.phx.gbl...
rowe_newsgroups wrote:
>On Feb 20, 1:55 pm, Rich <R...@discussions.microsoft.comwrote:
>>Is there a way to determine if a numeric value contains a decimal? how
to do
this?

If IsNumeric(txt1.Text) then ... so now I know that txt1.Text is a
numeric
value. How can I tell if it is a plain integer or decimal?

Thanks,
Rich

Parse the string for a period using IndexOf.

<pseudocode>

if IsNumeric(txt1.Text) then
if txt1.IndexOf(".") <-1 then
' Decimal
else
' Integer
end if
end if

</pseudocode>

Thanks,

Seth Rowe

That's assuming that the decimal separator is a period, which it isn't
everywhere.

The decimal separator for any given culture can be found in the
NumberFormat.NumberDecimalSeparator property.

--
Göran Andersson
_____
http://www.guffa.com
Couldn't you also do something along the lines of:

If IsNumeric(txt1.Text) Then
If CLng(txt1.Text) / 1 = CLng(txt1.Text) \ 1 Then
'Integer
Else
'Decimal
End If
End If

Or, if you're doing this a lot and making a decision based on it...

Public Function IsReal (ByVal Number As Object) As Integer
Dim i As Integer
i = -1 'Fail
If IsNumeric(Number) Then
If CLng(Number) / 1 = CLng(Number) \ 1 Then
i = 0 'Integer
Else
i = 1 'Real
End If
End If
Return i
End Function

If IsReal(txt1.Text) < 1 Then MessageBox.Show("I want a real!!!")
If IsReal(txt2.Text) <0 Then MessageBox.Show("I want an integerl!!!")

I've just realised that this wouldn't work for "4.000000", but I'll let you
have it anyway. :\

Feb 20 '07 #4
I guess there is no builtin mechanism for doing this. I really meant to
ask if there was a builtin mechanism for doing this. Appears not.

Thanks all for your replies.
"Rich" wrote:
Is there a way to determine if a numeric value contains a decimal? how to do
this?

If IsNumeric(txt1.Text) then ... so now I know that txt1.Text is a numeric
value. How can I tell if it is a plain integer or decimal?

Thanks,
Rich

Feb 20 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
5
by: David Garamond | last post by:
In Interbase and Firebird, NUMERIC is implemented as 64-bit integer. This limits the range to NUMERIC(18, *) but for many uses that's adequate. And moreover it's fast and efficient. Is there a...
7
by: BBFrost | last post by:
I'm receiving decimal values from database queries and placing them on a report page. The users want to see the following .... Db Value Display Value 123.3400 123.34...
1
by: Mike P | last post by:
I am using a stored procedure to get a value from a table, but the parameter I need to pass is a numeric data type in the table. The SQL Parameter object in .NET seems to support most of the SQL...
3
by: AdamM | last post by:
Hi all, What function lets me check a text string and determine if that string is really a int, float, double, etc. just formatted as a string? Thanks in advance! Adam
0
by: rajmgopal | last post by:
Hello Everyone I am getting the following error when i try to insert a record into Sql Server 2005 from my VB 2005 application. sqlEx = {"Error converting data type numeric to numeric."} I...
11
by: Pieter | last post by:
Hi, I'm having some troubles with my numeric-types in my VB.NET 2005 application, together with a SQL Server 2000. - I first used Single in my application, and Decimal in my database. But a...
13
by: nishit.gupta | last post by:
Is their any fuction available in C++ that can determine that a string contains a numeric value. The value cabn be in hex, int, float. i.e. "1256" , "123.566" , "0xffff" Thnx
8
by: Frank Swarbrick | last post by:
My DBA says that a column defined, for instance, as DECIMAL(11,2) and containing a value of 1.00 takes up no more space on the database disk than a column defined as DECIMAL(7,2) and containing a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.