Results 1 to 2 of 2
  1. #1
    Kami is offline Member
    Join Date
    Oct 2011
    Posts
    4
    Rep Power
    0

    Question Getting/changing the decimal symbol?

    I have a string containing a decimal number. But if I convert it to a float or double, the decimal symbol will either be be ignored or the method throw a NumberFormatException (I'm not sure which one) if the program is run on a machine with a different decimal symbol specified in the settings than what is used in the string, right?

    So, I thought I could either detect what decimal symbol the system uses and replace the one in the string with that, or for that internally change the setting itself, using the System.getProperty(String), which I had previously used for things like the new line character(s) and path separator. There doesn't seem to be a property for the decimal symbol though.

    I'm guessing there is a way to do this(because internationalization is important for most anything related to computers), but... how? I don't want to seem like the guy who just jumps in and demands someone else to write the code for him, but I have no idea how to do this.

  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 Re: Getting/changing the decimal symbol?

    If you have done simple wrapper conversion with the dot symbol as the decimal point it returns the same regardless of the decimal symbol you have set in the system.

    Java Code:
    		String strVal = "12.23";
    		System.out.println(Double.parseDouble(strVal));
    However, there are ways to we can consider the localizations.

Similar Threads

  1. Replies: 5
    Last Post: 08-25-2011, 07:32 PM
  2. Decimal to binary, octal to decimal
    By matejm1994 in forum New To Java
    Replies: 3
    Last Post: 12-26-2010, 09:59 AM
  3. Replies: 0
    Last Post: 08-14-2010, 10:09 AM
  4. Replies: 9
    Last Post: 10-18-2008, 08:26 PM
  5. Replies: 3
    Last Post: 05-01-2008, 08:30 AM

Tags for this Thread

Posting Permissions

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