www.webdeveloper.com
Results 1 to 4 of 4

Thread: Replace Comma With Period

  1. #1
    Join Date
    May 2013
    Posts
    5

    Question Replace Comma With Period

    I am working on a JavaScript that uses variables defined by another program. I sat it up to use periods for barometric pressure and GPS coordinates. Some countries use commas instead of periods. Is there an easy way to have the JavaScript change a variable if it has a comma instead of a period to a period but also to not mess it up if it already has a period?

    For example:

    var l = 39.4259
    var r = 30.06

    Now if the program is sat to use commas (changing those to 39,4259 and 30,06) how can I change those commas to periods only when commas are used?

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,674
    Code:
    function nocommas(val){return parseFloat(val.replace(/,/,'.'));}
    var l = nocommas('39,4259');
    alert('l = '+l+'; type of l = '+typeof l);

  3. #3
    Join Date
    May 2013
    Posts
    5
    Thanks.

  4. #4
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,674
    you welcome

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles