473,378 Members | 1,330 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,378 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 1483
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.