Results 1 to 7 of 7
  1. #1
    lrocha is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default Does regional settings matter when parsing Strings to numbers?

    Hi Guys, I have a question here. Does it matters the regional setting on my PC when parsing a String into a Double or into any other number?

    I am programming a formating module and I have to make a function that takes a Strings and returns a number, the problem is that I cant ensure the format of the input String becausse it will be send from different machines around the world!

    Can I asume that the format 231245.23 will always work when parsing it? Or it may not on other PCs???????

    what about numbers like:

    input should be
    213324,12 = 213324.12
    213,324.12 = 213324.12
    213.324,12 = 213324.12
    1`215.687,78= 1215687.78

    I was reading the API but I cant find any references of the format of the input String.

    Thanks in advance.
    Last edited by lrocha; 12-08-2010 at 04:34 PM. Reason: adding an example

  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
    20

    Default

    In simple word NO, it's nothing to do with your PC.

    In details, if your string in different character set (English, Chinese, etc..) then you are in trouble. Then you may need a better implementation. In what format your string is?

  3. #3
    lrocha is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default

    well I dont know the formar becausse it may be variable. I guess all the problem should be around the decimal and thousand separator chars.

    sometimes the decimal separator could be . or , some times the thousands separator could be . , or even nothing. I can set a configuration of decimal and thousands separator for an specific client and always turn the string into a ####.## format. But I am affraid that if my app is installed in a different server with different regional settings then the "." may not be still the decimal separator.

    Any ideas? AS I said the app will receive requests in xml from different PCs all over the world, specially from Japan but always in western char set! the problem is the Locale settings for dates and numbers. But now I will only concern about numbers!

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by lrocha View Post
    I am programming a formating module and I have to make a function that takes a Strings and returns a number, the problem is that I cant ensure the format of the input String becausse it will be send from different machines around the world!
    Do those numbers have to be send in text form? If so, make sure those numbers are formatted in an internationally accepted format, e.g. 123.45678;
    otherwise you have to know the locale of the sender and an entire mess is imminent. There are even formats from the East that are not directly supported by Java's number formatters.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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

    Default

    Quote Originally Posted by lrocha View Post
    But I am affraid that if my app is installed in a different server with different regional settings then the "." may not be still the decimal separator.
    Mainly those pin-points should be configurable within your application. So else you had to have a predefine mechanism to get those information, if necessary.

  6. #6
    saggio is offline Member
    Join Date
    Dec 2010
    Posts
    9
    Rep Power
    0

    Default

    maybe try formatting all of your input to make sure it's compatible?

    check the string, if a '.' comes before ',' then you can safely assume that '.' is the delimiter for thousands and ',' is the decimal delimiter.

    if the string only contains either '.' or ',' check where it occurs in the string to see if it is a decimal or thousands delimiter, etc. etc.

    then when you get all of those variables, you can format it so that it is consistent.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default

    if the string only contains either '.' or ',' check where it occurs in the string to see if it is a decimal or thousands delimiter
    Not a solution. How would you interpret 1.234 ? One point two three four OR one thousand two hundred thirty four?

    JosAH already posted the only correct advice.
    make sure those numbers are formatted in an internationally accepted format
    db

Similar Threads

  1. Replies: 1
    Last Post: 09-24-2010, 07:08 PM
  2. Replies: 4
    Last Post: 06-08-2010, 12:35 AM
  3. parsing numbers in a string
    By rsoler in forum Advanced Java
    Replies: 4
    Last Post: 03-31-2009, 06:05 AM
  4. Error message pops up no matter what?
    By murr0508 in forum New To Java
    Replies: 5
    Last Post: 02-26-2009, 10:10 PM
  5. printing two smallest numbers from a series of numbers
    By trofyscarz in forum New To Java
    Replies: 2
    Last Post: 10-14-2008, 11:46 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
  •