Prevent Number From Getting Rounded

R

rn5a

A Web Form has a TextBox within a DataGrid wherein users are expected
to enter only whole numbers. It should be validated so that the
TextBox doesn't remain blank or any non-numeric data is entered in the
TextBox. If the TextBox doesn't get validated, I want to display
messages to the user which should be as precise as possible for the
user to easily identify where he erred. This is how I did it:

==========================================
If (CType(ea.Item.Cells(4).Controls(1), TextBox).Text = "") Then
lblMessage.Text = "Quantity cannot be blank"
Else
If Not (IsNumeric(CType(ea.Item.Cells(4).Controls(1),
TextBox).Text)) Then
lblMessage.Text = "Quantity must be a number"
Else
Response.Write(CType(ea.Item.Cells(4).Controls(1),
TextBox).Text)
If (CType(ea.Item.Cells(4).Controls(1), TextBox).Text <= 0)
Then
lblMessage.Text = "Quantity must be greater than zero"
Else
Dim iQty As Integer

iQty = CInt(CType(ea.Item.Cells(4).Controls(1),
TextBox).Text)
.........................
.........................
.........................
End If
End If
End If
==========================================

The first 2 If conditions work correctly but the 3rd & the last one
doesn't. If I enter 0.8 in the TextBox, then it automatically gets
rounded to 1 & hence doesn't display the message "Quantity must be
greater than zero" though the Response.Write statement just before the
last If condition outputs the TextBox value as 0.8. Same is the case
if I enter 0.2 in the TextBox; it automatically gets rounded to 0.

How do I prevent the TextBox value from getting rounded when the Form
is submitted?
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

A Web Form has a TextBox within a DataGrid wherein users are expected
to enter only whole numbers. It should be validated so that the
TextBox doesn't remain blank or any non-numeric data is entered in the
TextBox. If the TextBox doesn't get validated, I want to display
messages to the user which should be as precise as possible for the
user to easily identify where he erred. This is how I did it:

==========================================
If (CType(ea.Item.Cells(4).Controls(1), TextBox).Text = "") Then
lblMessage.Text = "Quantity cannot be blank"
Else
If Not (IsNumeric(CType(ea.Item.Cells(4).Controls(1),
TextBox).Text)) Then
lblMessage.Text = "Quantity must be a number"
Else
Response.Write(CType(ea.Item.Cells(4).Controls(1),
TextBox).Text)
If (CType(ea.Item.Cells(4).Controls(1), TextBox).Text <= 0)
Then
lblMessage.Text = "Quantity must be greater than zero"
Else
Dim iQty As Integer

iQty = CInt(CType(ea.Item.Cells(4).Controls(1),
TextBox).Text)
.........................
.........................
.........................
End If
End If
End If
==========================================

The first 2 If conditions work correctly but the 3rd & the last one
doesn't. If I enter 0.8 in the TextBox, then it automatically gets
rounded to 1 & hence doesn't display the message "Quantity must be
greater than zero" though the Response.Write statement just before the
last If condition outputs the TextBox value as 0.8. Same is the case
if I enter 0.2 in the TextBox; it automatically gets rounded to 0.

How do I prevent the TextBox value from getting rounded when the Form
is submitted?

You are rounding the value when you convert it into an integer. When you
have determined that it's a number, convert into a Double, then do the
range check on the Double.
 
R

rn5a

You are rounding the value when you convert it into an integer. When you
have determined that it's a number, convert into a Double, then do the
range check on the Double.

--
Göran Andersson
_____http://www.guffa.com- Hide quoted text -

- Show quoted text -

Something's eerie somewhere in this Google archive because immediately
after posting my question in *this* thread, I had deleted it but Goran
still managed to answer it!!

Nevertheless, thanks a lot for your suggestion, Goran.
 
R

rn5a

You are rounding the value when you convert it into an integer. When you
have determined that it's a number, convert into a Double, then do the
range check on the Double.

--
Göran Andersson
_____http://www.guffa.com- Hide quoted text -

- Show quoted text -

Something's eerie somewhere in this Google archive because immediately
after posting my question in *this* thread, I had deleted it but Goran
still managed to answer it!!

Nevertheless, thanks a lot for your suggestion, Goran.
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Something's eerie somewhere in this Google archive because immediately
after posting my question in *this* thread, I had deleted it but Goran
still managed to answer it!!

Nevertheless, thanks a lot for your suggestion, Goran.

I am answering you in the newsgroup.

Deleting a post in a copy of the newsgroup doesn't delete it from the
newsgroup.
 
R

rn5a

I am answering you in the newsgroup.

Deleting a post in a copy of the newsgroup doesn't delete it from the
newsgroup.

Oops! I am sorry....after going through your response, I realized that
it's just a copy of the newsgroup.

BTW, any idea how does one delete his post from the original newsgroup?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top