Results 1 to 3 of 3

Thread: Format issue

  1. #1
    jomypgeorge is offline Member
    Join Date
    May 2010
    Posts
    90
    Rep Power
    0

    Default Format issue

    hi friends,
    i have an issue in formatting. i tried to pad zeros and add minus sign but it produce exception. but if i add plus sin then it works fine.

    class FormatTest1
    {
    public static void main(String ... args)
    {
    int i2 = 123456;
    System.out.format(">%2$+,09d< \n", i2,100000);
    }
    }

    it works ok
    but
    class FormatTest1
    {
    public static void main(String ... args)
    {
    int i2 = 123456;
    System.out.format(">%2$-,09d< \n", i2,100000);
    }
    }
    get exception

    whats happening here?
    cant we pad zeros with a minus sign?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,293
    Blog Entries
    7
    Rep Power
    24

    Default

    Quote Originally Posted by jomypgeorge View Post
    hi friends,
    i have an issue in formatting. i tried to pad zeros and add minus sign but it produce exception. but if i add plus sin then it works fine.

    class FormatTest1
    {
    public static void main(String ... args)
    {
    int i2 = 123456;
    System.out.format(">%2$+,09d< \n", i2,100000);
    }
    }

    it works ok
    but
    class FormatTest1
    {
    public static void main(String ... args)
    {
    int i2 = 123456;
    System.out.format(">%2$-,09d< \n", i2,100000);
    }
    }
    get exception

    whats happening here?
    cant we pad zeros with a minus sign?
    It has nothing to do with negative numbers, you're asking the formatter to left justify a number and pad it with zeros (on the left). It can't do that. Either leave out the minus sign or the zero.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    jomypgeorge is offline Member
    Join Date
    May 2010
    Posts
    90
    Rep Power
    0

    Default

    thanks JosAH

    i thought "-" is used to add minus sign is number < 0 and "+" is to add plus if >0
    for that "+" itself is enough.
    yeah i got it ....

Similar Threads

  1. Format the output
    By Moustafa taha in forum New To Java
    Replies: 5
    Last Post: 10-18-2010, 05:01 AM
  2. What format is a getText()?
    By AJArmstron@aol.com in forum New To Java
    Replies: 1
    Last Post: 04-18-2010, 01:43 AM
  3. JSP code format
    By joeyxaza in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 02-20-2009, 06:11 PM
  4. how to convert one format to another format
    By mahipal_reddy621 in forum New To Java
    Replies: 1
    Last Post: 12-02-2008, 11:21 AM
  5. Format
    By 2ndis1stplaceloser in forum New To Java
    Replies: 2
    Last Post: 10-21-2008, 06:38 AM

Posting Permissions

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