Results 1 to 3 of 3
  1. #1
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default why wont the %.2f work here?

    as the title says, I keep getting issues here, it will compile but wont format the decimal 2 places and give me an error

    System.out.printf("Sorry, you need $%.2f", +cashNeeded+ "more.%n");

    also cashNeeded is saved as a double

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

    Default

    You're sort of mixing printf() and print()-style concatenation. WHat you do is put *all* of the content into the format string:

    Java Code:
    System.out.printf("Sorry, you need $%.2f more.%n", cashNeeded);

  3. #3
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

Similar Threads

  1. importing JCurses wont work!
    By TheBreadCat in forum New To Java
    Replies: 0
    Last Post: 02-16-2011, 08:46 PM
  2. class that wont work out properly.
    By vampire-elf in forum New To Java
    Replies: 7
    Last Post: 09-07-2010, 01:39 AM
  3. JApplet buttons wont work
    By Mark101 in forum New To Java
    Replies: 3
    Last Post: 03-16-2010, 06:53 PM
  4. Why wont import jm.util.*; work??
    By cakepizza in forum New To Java
    Replies: 2
    Last Post: 01-01-2010, 11:19 PM
  5. save will work but load wont?!?!
    By Sticks_ll in forum New To Java
    Replies: 1
    Last Post: 06-12-2008, 04:19 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
  •