Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By JosAH

Thread: Formating numbers makes wierd letter insead of comma.

  1. #1
    Dowie is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Formating numbers makes wierd letter insead of comma.

    So, I'm trying to learn to format numbers, but when i try this code in the compiler it results in this:

    Java Code:
    public class FormatTest {
    	public static void main(String[] args) {
    		String y = String.format("%, d", 1000000000);
    		System.out.println(y);
    	}
    }
    Formating numbers makes wierd letter insead of comma.-formatwierd.jpg

    Is there something I'm doing wrong here?

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: Formating numbers makes wierd letter insead of comma.

    It should work fine that way. Is there anything special with your Windows command prompt? Try display the string using a Swing component to see if the command prompt is the problem. Use the code below.

    Java Code:
    JOptionPane.showMessageDialog(null, y);

  3. #3
    Dowie is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Re: Formating numbers makes wierd letter insead of comma.

    It shows this:

    Formating numbers makes wierd letter insead of comma.-messageformat.jpg

    There is supposed to be commas instead of spaces there right?

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: Formating numbers makes wierd letter insead of comma.

    Is there any possibility that it was not a comma that you type in your code? Which editor that you use to write the code? There something going on with the source file I guess.

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

    Default Re: Formating numbers makes wierd letter insead of comma.

    That funny character is a locale specific separator character but your font can't display it.

    kind regards,

    Jos
    DarrylBurke likes this.
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: Formating numbers makes wierd letter insead of comma.

    It means that the OP operating system default locale might be set to something that the output system can't display?

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

    Default Re: Formating numbers makes wierd letter insead of comma.

    Quote Originally Posted by wsaryada View Post
    It means that the OP operating system default locale might be set to something that the output system can't display?
    Yep, the OP can check this by inspecting the DecimalFormatSymbols class; (the grouping character can be changed).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: Formating numbers makes wierd letter insead of comma.

    Quote Originally Posted by JosAH View Post
    That funny character is a locale specific separator character but your font can't display it.
    Good thinking, Jos.

    The 'funny character' is the non-breaking space, "\00A0"

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: Formating numbers makes wierd letter insead of comma.

    Quote Originally Posted by wsaryada View Post
    It means that the OP operating system default locale might be set to something that the output system can't display?
    I'm not about to change my system locale to check, but I wouldn't expect any Windows command prompt to display a non-breaking space correctly.

    No idea whether Linux/MacOS would be any different.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

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

    Default Re: Formating numbers makes wierd letter insead of comma.

    Quote Originally Posted by DarrylBurke View Post
    Good thinking, Jos.

    The 'funny character' is the non-breaking space, "\00A0"
    That explains it all; look how that dialog displays the number; possibly that's how the OP's locale wants to display it (groups of three digits separated by a space character); of course that silly MS Windows shell can't display those characters ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. JPanel on JFrame wierd problem
    By IndiDev in forum AWT / Swing
    Replies: 3
    Last Post: 02-06-2012, 08:30 PM
  2. wierd NetBeans problem.
    By edi.gotieb in forum Forum Lobby
    Replies: 2
    Last Post: 10-09-2010, 02:31 PM
  3. Formatting numbers or decimals (around comma)
    By Joris in forum Advanced Java
    Replies: 1
    Last Post: 04-22-2010, 06:46 PM
  4. Problem with formating comments
    By Lubomirus in forum Eclipse
    Replies: 0
    Last Post: 07-07-2009, 09:37 AM
  5. wierd problem
    By f_the_cook in forum Advanced Java
    Replies: 4
    Last Post: 10-09-2008, 06:13 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
  •