CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    [RESOLVED] javascript and globalization

    I have website where users can use the language of their preference.

    So far, a user can choose between English and Dutch. When they want to store the numeric value 0.25, they need to enter 0.25 for English and 0,25 for Dutch. So far it works fine.

    Now comes the problem. I want to do some clientside calculations base on the user input, just for their clarity. I have 2 input fields (both with decimal values), I want to divide them and show the result in another input field.

    Now, the problem is, that when I enter 0,25 (dutch version) in the second field, javascript interprets this as 0. it simply ignores everything behind the ','. Looks like javascript has English as its language.

    Is there anyway to set the globalization culture of javascript?

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: javascript and globalization

    Not directly. Your best option is to use a temporary variable to do calculations. With that variable, string replace all commas to periods. Then do the calculations.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jul 2005
    Location
    Currently in Mexico City
    Posts
    568

    Re: javascript and globalization

    Yes, js speaks "English". You would need to take input "number" as text and then manually parse it converting to real number (detect language and then replace comma with dot if it's Dutch).
    Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?

    I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)

    //always looking for job opportunities in AU/NZ/US/CA/Europe :P
    willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));

    USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!

  4. #4
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: javascript and globalization

    Ok that's clear.

    In the mean while, I found a JQuery plugin that can do calculations in English en Dutch format.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured