473,387 Members | 1,440 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,387 software developers and data experts.

format textbox value as number

nic
Hi,
I have a textbox value that I need to force (and format)
to be a numeric value. For example, I want to allow a
user to type 1000 or 1,000 or 1,000,000 but not something
that is not numberic. Essentially I want to ignore the
commas. If I use the compareValidator it does not allow
commas. Is there an easy way to do this? Also I need to
format a string such as 1000 as 1,000 (without any decimal
places) When I format 1000 as a numeric it returns
1,000.00.

Thanks
Nov 18 '05 #1
1 3450
Hi Nic,

You can use Format strings to do the output generation. ToString("C")
generates numbers with the thousands separators, but unfortunately also with
the $. You can also build custom format strings, but offhand I can't
remember the format - look in the MSDN docs.

On the way in you can use decimal.Parse() with options that strip that stuff
out. I use the following in my DataBinding Controls which do the conversion
automatically.

Decimal.Parse( (string) loValue,NumberStyles.Any);

This doesn't address the client side Validators. For that you probably will
neeed to use the RegEx validation control.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/blog/
----------------------------------
Making waves on the Web
"nic" <an*******@discussions.microsoft.com> wrote in message
news:15*****************************@phx.gbl...
Hi,
I have a textbox value that I need to force (and format)
to be a numeric value. For example, I want to allow a
user to type 1000 or 1,000 or 1,000,000 but not something
that is not numberic. Essentially I want to ignore the
commas. If I use the compareValidator it does not allow
commas. Is there an easy way to do this? Also I need to
format a string such as 1000 as 1,000 (without any decimal
places) When I format 1000 as a numeric it returns
1,000.00.

Thanks

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: H Branyan | last post by:
I need to format a textbox value a user enters. The user will enter 13 characters, and then I have to format them, preferably in the onBlur event, to look like this: XXXX-XX-XXX-XXXX I found...
0
by: Mark | last post by:
All, Excuse the re-post but I have found something which works for the UserID but not for the Password (see previous post below). The problem is I don't understand how it works and therefore...
2
by: Juan | last post by:
I get a number from db and display it in a textbox control, how can i format the value as currency? thanks, Juan.
5
by: Claudia Fong | last post by:
Hi, I have 2 forms. Form1 has a button which calls form2, but I need to know the value of the form1.textBox1.text. When I show form2, I try to use the code bellow: textBox1.Text =...
4
by: Art | last post by:
Hi, I have a MyTextBox class that inherits from TextBox. How do I make it display the information as, say 0.00. Sometimes the value will be typed by the user. Other times the value will be...
15
by: staeri | last post by:
I'm looping through some textboxes to sum the values. If the value in the textbox has a dot or a space as thousand separator the sum function doesn't work. Can someone help me to make it work...
3
by: RevUK | last post by:
Hi, I am trying to link a textbox value from an Access 97 form to a specific cell in Excel 97. I have tried many different avenues with this but as of yet I am still stuck on how to achieve...
1
by: yegeswari | last post by:
Hi, How to validate given textbox value is number only. Suppose given text value is other than number mean it should give an alert message. Thanks and regards, Yegeswari
2
by: digituf | last post by:
may i know if in php i can assign the textbox value from the user input as variables and then display the result of in the same page. assume, user insert the checkin and checkout date, then it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.