Results 1 to 7 of 7
  1. #1
    halyal is offline Member
    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0

    Default does Double.parseDouble respect unicode

    I have a class which extends jTextField.
    The keytyped event allows on characters that are isDigit() or "." or "-"
    it works fine with english as well as local language unicode font.

    (The numerals are displayed differently but the isdigit works fine)

    but if i say Double.parseDouble to english numeral it works but for local numerals it fails
    (the english and local numerals are in the same unicode font).

    How come isDigit and parseDouble work differently and what will be the workaround.

    Image of numerals attached.
    Rajesh
    Attached Thumbnails Attached Thumbnails does Double.parseDouble respect unicode-numerals.jpg  

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Might be matching all Unicode characters with Number property all you need. Something like "\\p{N}+".

  3. #3
    halyal is offline Member
    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0

    Default

    Sorry for my ignorance but could you be more elaborate
    Rajesh

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Did you get the meaning of that pattern?There \p syntax is listed as the supporting Unicode categories available. N is abbreviated as number category.

    UTS #18: Unicode Regular Expressions

    Actually you have to do kind of analysis for that.

  5. #5
    halyal is offline Member
    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0

    Default this seems something difficult to understand for my minuscule brain

    this seems something difficult to understand for my minuscule brain.
    will try it out in one or two days.
    java seems a bit difficult as RAD tool.
    Rajesh

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    parseDouble (and the float parsing which it uses) aren't locale specific, so they don't work with non-ASCII numerals. If you need locale specific, then use NumberFormat.

    I think that's correct anyway.

    Which means you need to know what locale you're attempting to parse from.

  7. #7
    halyal is offline Member
    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0

Similar Threads

  1. double a * double b = weird output
    By GPB in forum New To Java
    Replies: 3
    Last Post: 03-26-2010, 10:40 AM
  2. Check if double is double
    By marshalthrone in forum New To Java
    Replies: 8
    Last Post: 09-30-2009, 02:51 PM
  3. Replies: 5
    Last Post: 03-21-2009, 09:32 PM
  4. Double.valueOf() vs Double.parseDouble()
    By greenbean in forum New To Java
    Replies: 10
    Last Post: 01-12-2009, 08:39 AM
  5. Urgent-Imp-Displaying message with respect to system time
    By garinapavan in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 02:17 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
  •