Results 1 to 4 of 4
  1. #1
    kmckinley820 is offline Member
    Join Date
    Feb 2011
    Posts
    7
    Rep Power
    0

    Default Display a '%' when using String.format( )

    I am writing a program where I need to display the percent symbol '%' in a GUI using String.format( ). Since % is used as the indicator to place args in the String I can't figure out how to display '%'.

    example:

    float percent = 20;

    String Sentence = String.format("You are %,.2f done.", percent);



    this would only display 20.00
    How do I get it to display like 20.00% ????

    Thanks.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    Use %%
    Java Code:
    String Sentence = String.format("You are %,.2f%% done.", percent);
    Or format only the first part and append the rest
    Java Code:
    String Sentence = String.format("You are %,.2f", percent)+ "% done";
    ;D

  3. #3
    kmckinley820 is offline Member
    Join Date
    Feb 2011
    Posts
    7
    Rep Power
    0

    Default

    Exactly what I needed!

    Thanks!!!

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    If you are done please mark your thread solved with the thread tools at the top, glad you got what you were looking for.

Similar Threads

  1. how to display data in a table format using jstl tag
    By anand12356 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 02-09-2011, 01:26 PM
  2. how to set display format into a column in jTable?
    By newbiejava in forum New To Java
    Replies: 1
    Last Post: 07-27-2010, 04:54 PM
  3. Replies: 1
    Last Post: 05-31-2010, 08:46 AM
  4. Java Locale Date Display Diff Format Prob
    By hemanthjava in forum Advanced Java
    Replies: 2
    Last Post: 03-05-2009, 02:05 PM
  5. Date format display in CSV file after exporting
    By latha in forum Advanced Java
    Replies: 0
    Last Post: 08-03-2007, 08:09 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
  •