473,761 Members | 9,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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).Contro ls(1), TextBox).Text = "") Then
lblMessage.Text = "Quantity cannot be blank"
Else
If Not (IsNumeric(CTyp e(ea.Item.Cells (4).Controls(1) ,
TextBox).Text)) Then
lblMessage.Text = "Quantity must be a number"
Else
Response.Write( CType(ea.Item.C ells(4).Control s(1),
TextBox).Text)
If (CType(ea.Item. Cells(4).Contro ls(1), TextBox).Text <= 0)
Then
lblMessage.Text = "Quantity must be greater than zero"
Else
Dim iQty As Integer

iQty = CInt(CType(ea.I tem.Cells(4).Co ntrols(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 1512
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).Contro ls(1), TextBox).Text = "") Then
lblMessage.Text = "Quantity cannot be blank"
Else
If Not (IsNumeric(CTyp e(ea.Item.Cells (4).Controls(1) ,
TextBox).Text)) Then
lblMessage.Text = "Quantity must be a number"
Else
Response.Write( CType(ea.Item.C ells(4).Control s(1),
TextBox).Text)
If (CType(ea.Item. Cells(4).Contro ls(1), TextBox).Text <= 0)
Then
lblMessage.Text = "Quantity must be greater than zero"
Else
Dim iQty As Integer

iQty = CInt(CType(ea.I tem.Cells(4).Co ntrols(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.com wrote:
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).Contro ls(1), TextBox).Text = "") Then
lblMessage.Text = "Quantity cannot be blank"
Else
If Not (IsNumeric(CTyp e(ea.Item.Cells (4).Controls(1) ,
TextBox).Text)) Then
lblMessage.Text = "Quantity must be a number"
Else
Response.Write( CType(ea.Item.C ells(4).Control s(1),
TextBox).Text)
If (CType(ea.Item. Cells(4).Contro ls(1), TextBox).Text <= 0)
Then
lblMessage.Text = "Quantity must be greater than zero"
Else
Dim iQty As Integer
iQty = CInt(CType(ea.I tem.Cells(4).Co ntrols(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.com wrote:
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).Contro ls(1), TextBox).Text = "") Then
lblMessage.Text = "Quantity cannot be blank"
Else
If Not (IsNumeric(CTyp e(ea.Item.Cells (4).Controls(1) ,
TextBox).Text)) Then
lblMessage.Text = "Quantity must be a number"
Else
Response.Write( CType(ea.Item.C ells(4).Control s(1),
TextBox).Text)
If (CType(ea.Item. Cells(4).Contro ls(1), TextBox).Text <= 0)
Then
lblMessage.Text = "Quantity must be greater than zero"
Else
Dim iQty As Integer
iQty = CInt(CType(ea.I tem.Cells(4).Co ntrols(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.com wrote:
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
8328
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 we get an interest payment. Unless the bank is cruel to its developers the interest figure will be able to be exactly represented by a computer, something like 4.1% as opposed to 4 1/3 % 125.78 * ' Initial Balance 04.1% -------
2
2552
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 function redondeo(valor){ valor= valor *100;
2
6235
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. When I load the stylesheet & do the transform from my VB.NET or C# code however (i.e. using system.xml etc) I always get NaN returned. I don't know why, it took me ages to work it out but the fix is to cast the first parameter in the...
32
76450
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 */ int is_prime_number(int n)
52
1565
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places? ----------------------------------------------------------------------- When formatting money for example, to format 6.57634 to 6.58, 6.5 to 6.50, and 6 to 6.00? Rounding of x.xx5 is uncertain, as such numbers are not represented exactly.
6
3197
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 a number. I need to round to the nearest .05. For example: 5.36 would be rounded to 5.35, 10.49 would be rounded to 10.50, etc.. Any help would be greatly appreciated.
16
2897
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, but that looks difficult. I don't mind something which is system-specific; the older gccs had various defines in cpu_limits.h and related files, but I can't find anything in later gccs.
1
1371
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 values. Does my sql need to return the items, and i then manually summate these values by reading each one by one, or can I do this in the sql. Remember, I still need to round on an invoice by invoice basis. My sql which returns rounded invoice totals...
30
29655
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 expected my_round(2.5) = 2 # Not 3, which is an odd num I'm interested in rounding numbers of the form "x.5" depending upon whether x is odd or even. Any idea about how to implement it ?
0
9345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8780
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5229
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.