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

Working with numbers

Ike
Anyone know of a quick method to make numbers input from a textbox work with
math. For example, if I have a text box where people might enter a value
like:

$567,000.23

I want to work with only 567000.23

Is there an easy way to do that? Thanks, Ike
Jul 23 '05 #1
3 1201
*Ike* wrote:
Anyone know of a quick method to make numbers input from a textbox
work with math. For example, if I have a text box where people might
enter a value like:

$567,000.23

I want to work with only 567000.23

Is there an easy way to do that? Thanks, Ike


To reduce the degree of variation in the input data I'd provide the user
with unambiguous input boxes where the currency unit can be selected in
isolation, the integer money units are then input in one box and the
small change goes in another box. That way the user doesn't have to make
any decisions as to what the currency format should be since there is no
choice! Any extraneous characters in the input can then be queried more
successfully.

That said, if you don't want to do that then the following is a starter:

var strInput = "$567,000.23";
var dblInput = strInput.replace(/[^\d\.]/g, "");

You can then check isNaN(dblInput). However, the above won't work for
the large number of countries that interchange . and , delimiters in
numbers - e.g. the above won't work for: Euro567.000,23
--
Andrew Urquhart
- FAQ: www.jibbering.com/faq/
- Archive: www.google.com/groups?q=comp.lang.javascript
- My reply address is invalid, see www.andrewu.co.uk/contact/
Jul 23 '05 #2
Ike wrote:
Anyone know of a quick method to make numbers input from a textbox work with
math. For example, if I have a text box where people might enter a value
like:

$567,000.23

I want to work with only 567000.23

Is there an easy way to do that? Thanks, Ike


value= + (value.replace(/[$,]/g,""))
if(!isNaN(value)){
// It's a number, use number in calculations
}

Place any unwanted character into the bracket.

[Ł˘ $Ą,€]

Pound sterling, US cent, space, US dollar, yen, euro.
Mick
Jul 23 '05 #3
JRS: In article <KI***************@newsfe6-gui.server.ntli.net>, seen
in news:comp.lang.javascript, Andrew Urquhart <useWebsiteInSignatureToRe
pl*@spam.invalid> posted at Tue, 29 Jun 2004 12:59:08 :

You can then check isNaN(dblInput). However, the above won't work for
the large number of countries that interchange . and , delimiters in
numbers - e.g. the above won't work for: Euro567.000,23


The browser's decimal separator is
Char = 1.5.toString().charAt(1) // tested only in UK IE4
// (3/2) might be safer

I don't know of anywhere offhand that uses a character other than the
(keyboard) . or , characters, ASCII 46 and 44. Anyone?

But there may well be one or more other Unicode decimal separators; and,
if so, I know of one person who, it must be supposed, would use nothing
but one of those.

In addition to stripping the expected, or any, unwanted characters, one
can if necessary rectify the decimal separator before conversion to
Number.

Actually, one should not strip the currency indication; if it can be
ignored, it should be forbidden, and otherwise it needs to be
considered.

In some contests, it may be necessary to consider alien formats for
negative numbers.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links;
some Astro stuff via astro.htm, gravity0.htm; quotes.htm; pascal.htm; &c, &c.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 23 '05 #4

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

Similar topics

1
by: Scott David Daniels | last post by:
I've been working on a module to get at the bits of all numeric types (no, I haven't thought of how to solve the decimal data type that is coming). I've finally got the bits module to pass all of...
14
by: David Shaw | last post by:
Hi, I'm writing a fun little program to play "Petals Around the Roses" with... I need to seed my random numbers so that they won't be the same every time I run the program, but my compiler won't...
6
by: massimo | last post by:
Hey, I wrote this program which should take the numbers entered and sort them out. It doesnąt matter what order, if decreasing or increasing. I guess I'm confused in the sorting part. Anyone...
5
by: Todd Steury | last post by:
Greetings Python'ers: I'm just an amature who occasionally uses Python for complex mathematical models. The current model I'm working with occasionally generates really large numbers that are...
5
by: michael sorens | last post by:
I have a form with a variety of controls (TextBox, CheckBox, and Button). I have assigned TabIndex values starting from 1 at the top, working my way down the form to 15 at the bottom. Each of these...
11
by: Girish Sahani | last post by:
I wrote the following code to concatenate every 2 keys of a dictionary and their corresponding values. e.g if i have tiDict1 = tiDict1 = {'a':,'b':} i should get tiDict2={'ab':} and similarly for...
39
by: Frederick Gotham | last post by:
I have a general idea about how negative number systems work, but I'd appreciate some clarification if anyone would be willing to help me. Let's assume we're working with an 8-Bit signed integer,...
5
by: sesling | last post by:
I have a database field that stores 8 and 9 digit values. I need to calculate the sum value using the first 8 digits. ex.of stored numbers 123456781 234567892 45678903 ...
9
by: Aamir Mahmood | last post by:
Hi, I have working on a system in which I have to manipulate *very* big numbers. Like 32368060745625089670148189374568111100874165870871388541651800834565616109380834613212956588769877 They...
2
by: obtrs | last post by:
im using java script for form validation.. here is the code <script type="text/JavaScript"> function validate_required(field,alerttxt) { with (field)
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: 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...
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
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...
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.