Re: How to convert International number strings to their number va



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.
>
.



Relevant Pages

  • Re: CDBL Function truncates decimals
    ... Is there a way to format a number into US ... Public Function ConvertNumberforSQL (ByVal sValue As String, ... Since the Spanish formatting has a comma, the SQL statement seems to have ...
    (microsoft.public.vb.general.discussion)
  • Re: Handling floating point with decimal comma separator to filter a form
    ... Lets say the user wants to filter values between 1,1 and 1,9 (note that the user wiil enter the number with a comma sparator, not with a dot - and the Standard format will be of no help here). ... Dim strWhere As String ...
    (microsoft.public.access.formscoding)
  • Re: Concatenated numerical literals
    ... commas and currency symbol and hacked it a little to make ... import types, string ... This function will take the number passed to it and format it as US ... comma separators and two decimal places ...
    (comp.lang.python)
  • comp.lang.javascript FAQ - Quick Answers 2009-03-02
    ... (loosely called javascript), and some hints and tips to make your ... A date can be formatted to a common ISO 8601 format with:- ... _How do I format a Number as a String with exactly 2 decimal places_? ... Or Wednesdays FAQ posting. ...
    (comp.lang.javascript)
  • How to convert International number strings to their number values
    ... The JavaScript Numberfunction does not work correctly. ... convert a string that contains a comma to a number. ... German does not help. ...
    (microsoft.public.scripting.jscript)