Re: How to convert International number strings to their number va
- From: Ray White <RayWhite@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 23 Jul 2005 21:43:01 -0700
I feel as though I am being scolded for asking such a question. As if I do
not know the difference between U.S. number formats and others around the
world. That is not true. I have written International software for over a
decade. Yes, I am an American, but I work hard to ensure that my software
works in every locale. I just don't understand why the Number() function
fails to honor the Regional Language Options settings. If the locale number
format uses a comma, then the Number format should honor that. If it uses a
period, then it should honor that. It should not insist that a period be
used. That is wrong.
--ray
"Dr John Stockton" wrote:
> JRS: In article <F20CF8E2-6B5A-49F2-B4CF-EA4E00657FC3@xxxxxxxxxxxxx>,
> dated Fri, 22 Jul 2005 07:58:04, seen in news:microsoft.public.scripting
> ..jscript, Ray White <Ray@White.?.microsoft.com> posted :
>
> >The JavaScript Number() function does not work correctly.
>
> > It will not
> >convert a string that contains a comma to a number.
>
> Can you find a statement that it should do so in the language standard
> ECMA-262? Indeed, section 9.3.1 shows clearly that only a dot is
> acceptable.
>
>
> > Commas are used as
> >decimal points in locales outside the U.S.
>
> In some such locations. They are also used as thousands separators.
>
>
> > However, the JavaScript Number()
> >function returns the error "-1.#IND" when you try to use a comma in the
> >string parameter.
>
> Your system may do that; in my IE4, Number() does not; it gives NaN.
> This is not a WSH group; if using WSH, you should say so, because the
> common assumption may be that code is for the Web.
>
>
> > Changing the Regional Language settings in the OS to
> >German does not help. In fact, when JavaScript runs on a German XP OS, it
> >still gives this error.
>
> There is no way in which the Number function can tell whether a string
> is of internal or external origin. If it behaves as you want, then code
> to be executed in comma-using localisations would have to have some of
> its dots changed to commas. Code is not necessarily executed where it
> is written.
>
>
> >How can I convert an international string to a number in JavaScript?
>
> Using "international" to mean "foreign" is bad-mannered; it conveys a
> lack of recognition that the USA is merely one of about 200 countries,
> all different. Eschew.
>
>
> Note that 1,234 has one meaning in the UK and another in France;
> automatic discrimination is not possible.
>
> Note also that, when the value of 3/2 is output as a string, one can see
> the decimal separator used. You may also need to edit your outputs.
>
> See <URL:http://www.merlyn.demon.co.uk/js-maths.htm#DPV>.
>
> --
> © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
> <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
> <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
> <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
>
.
- Follow-Ups:
- Re: How to convert International number strings to their number va
- From: Dr John Stockton
- Re: How to convert International number strings to their number va
- References:
- How to convert International number strings to their number values
- From: Ray White
- Re: How to convert International number strings to their number values
- From: Dr John Stockton
- How to convert International number strings to their number values
- Prev by Date: Re: Validate date
- Next by Date: Re: hiding rows in a table
- Previous by thread: Re: How to convert International number strings to their number values
- Next by thread: Re: How to convert International number strings to their number va
- Index(es):
Relevant Pages
|