472,363 Members | 2,007 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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 1422
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: John Bentley | last post by:
John Bentley writes at this level: If we think about our savings accounts then division never comes in (as far as I can see). We deposit and withdraw exact amounts most of the time. Occasionaly...
2
by: SoLRaC | last post by:
I have a form, and i want with javascript round a number with 2 decimals to de uper next 0 or five. IE if you have the number 4,53 it must be rounded to 4,55. Until now i wrote that var valor...
2
by: Jim Craig | last post by:
When I do a transform with a stylesheet containing the function format-number($varname,'#,##0.00') from XSLerator (which uses MSXML) I get the result I expect, a decimal number rounded to 2 places....
32
by: Cmorriskuerten | last post by:
HI, is this is this solution to test if a number is a prime number or not: /* * Is n a prime number? * Return TRUE (1): n is a prime number * Return FALSE (0): n is a *not* a prime number...
52
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
6
by: dkirkdrei | last post by:
I am looking for a way to round a number (which will be displayed as a dollar amount) to the nearest nickel. Using the php round function only allows you to control the number of decimal places in...
16
by: Dom Fulton | last post by:
Has anyone got a mechanism for finding the number of bits in floats, doubles, and long doubles? I need this to communicate with some hardware. I guess I could try to deduce this from float.h,...
1
by: ZiggyShort | last post by:
I need to summate across a number of line items over a group of invoices, then round down on an invoice by invoice basis to the nearest penny. I would then like to get a total of THOSE rounded...
30
by: bdsatish | last post by:
The built-in function round( ) will always "round up", that is 1.5 is rounded to 2.0 and 2.5 is rounded to 3.0. If I want to round to the nearest even, that is my_round(1.5) = 2 # As...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.