Results 1 to 4 of 4
  1. #1
    Ike
    Ike is offline Member
    Join Date
    Aug 2011
    Posts
    21
    Rep Power
    0

    Default How to set string/number length?

    I have to print a value in aJFrame, but since it's double it is too long.
    I'm currently using:

    g.drawString("ValueOfSOmething = " + doubleNumber, x, y );


    What should I do to set length?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: How to set string/number length?

    You can use the String method format().

    Something like g.drawString(String.format("ValueOfSOmething = %.2f", doubleNumber), x, y );

  3. #3
    Ike
    Ike is offline Member
    Join Date
    Aug 2011
    Posts
    21
    Rep Power
    0

    Default Re: How to set string/number length?

    Thank you very much. It works great.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

Similar Threads

  1. Replies: 11
    Last Post: 08-15-2011, 11:12 AM
  2. String.length?
    By rizowski in forum New To Java
    Replies: 7
    Last Post: 11-20-2010, 06:33 PM
  3. string length HELP PLZ!!
    By vette427 in forum Eclipse
    Replies: 1
    Last Post: 09-23-2010, 07:12 AM
  4. Validating for length of String
    By Bascotie in forum New To Java
    Replies: 1
    Last Post: 10-11-2009, 12:45 PM
  5. finding length on a number
    By thekrazykid in forum New To Java
    Replies: 8
    Last Post: 12-12-2008, 09:07 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
  •