469,920 Members | 2,190 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,920 developers. It's quick & easy.

Prevent Number From Getting Rounded

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?

Feb 27 '07 #1
5 1329
rn**@rediffmail.com wrote:
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.

--
Göran Andersson
_____
http://www.guffa.com
Feb 27 '07 #2
On Feb 27, 1:08 pm, Göran Andersson <g...@guffa.comwrote:
r...@rediffmail.com wrote:
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.

--
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.

Feb 28 '07 #3
On Feb 27, 1:08 pm, Göran Andersson <g...@guffa.comwrote:
r...@rediffmail.com wrote:
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.

--
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.

Feb 28 '07 #4
rn**@rediffmail.com wrote:
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.

--
Göran Andersson
_____
http://www.guffa.com
Feb 28 '07 #5
On Mar 1, 2:09 am, Göran Andersson <g...@guffa.comwrote:
r...@rediffmail.com wrote:
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.

--
Göran Andersson
_____http://www.guffa.com
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?

Mar 1 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by SoLRaC | last post: by
2 posts views Thread by Jim Craig | last post: by
32 posts views Thread by Cmorriskuerten | last post: by
6 posts views Thread by dkirkdrei | last post: by
16 posts views Thread by Dom Fulton | last post: by
30 posts views Thread by bdsatish | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.