Results 1 to 2 of 2
  1. #1
    plm-pusik is offline Member
    Join Date
    Aug 2010
    Posts
    17
    Rep Power
    0

    Default Scanner/Locale Trouble

    (The title is misleading, this post has nothing to do with the Scanner class. Before I edited my post it had to do with the Scanner class, but not anymore).

    Hey, I've made a simple GUI which contains some JTextFields (Swing) where the user gets to input a double (but since it's JTextFields the input gets stored in a String). In order to process inputed string and to extract the double I use Double.parseDouble(inputedString).
    But it says it's an invalid input if I enter for example "3,14". Observe, ',' decimal point instead of a '.' (because it's swedish standards). So in order to get around this I tried adding this in the beginning of my code:
    Java Code:
    Locale.setDefault(new Locale("sv","SE")); //according to this book I got, this should set it to swedish standards
    This kind of works since my program now outputs doubles with a ',' as decimal point. But I still can't input using a ','. Help? Let me know if you need the rest of my code.

    Thanks.
    Last edited by plm-pusik; 10-15-2010 at 05:45 PM.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    See the API docs for DecimalFormat and it's parse method. And make sure to read the entire method description carefully.

Similar Threads

  1. trouble with Scanner(new File("input"));
    By ronyosi in forum New To Java
    Replies: 9
    Last Post: 10-27-2010, 11:34 PM
  2. Scanner Trouble
    By Snoman in forum New To Java
    Replies: 3
    Last Post: 09-28-2010, 05:29 AM
  3. Replies: 0
    Last Post: 12-01-2008, 09:50 PM
  4. Locale example
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-29-2008, 09:04 AM
  5. Locale
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-16-2007, 02:16 PM

Posting Permissions

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