Results 1 to 6 of 6
  1. #1
    lala is offline Member
    Join Date
    Oct 2010
    Posts
    80
    Rep Power
    0

    Default 2 decimal places needed

    Hello All.
    I tried this format:
    Java Code:
    double homePrice;
    String.format("%.2f", homePrice);
    but I am not getting 2 decimal places that i need.
    ex. I get $100000.0 Even if I type 100 I get 100.0 (?)
    Thanks In Advance

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    How exactly are you executing the code?
    Java Code:
    		double homePrice = 100;
    		String x = String.format("%.2f", homePrice);
    		System.out.println(x);
    Java Code:
    run:
    100.00
    BUILD SUCCESSFUL (total time: 1 second)
    That's my code/output.

  3. #3
    lala is offline Member
    Join Date
    Oct 2010
    Posts
    80
    Rep Power
    0

    Default 2 decimal places needed

    Could this "homePrice =" statement have anything to do with the output formatting not coming out as 2 decimals?:confused: :confused:
    I tried your suggestion Zack.

    Java Code:
    homePrice = Double.parseDouble(inputStr);
    		String x = String.format("%.2f", homePrice);

  4. #4
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    How are you now outputting x? As long as homePrice has a value it should force the two decimal places.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default

    Continued from Three Different Dialogue Boxes

    db

  6. #6
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    lala I showed you this in that thread Darryl.Burke is linking to

Similar Threads

  1. round to two decimal places
    By javaMike in forum New To Java
    Replies: 3
    Last Post: 12-24-2011, 02:01 AM
  2. Limiting decimal places in a double
    By darek9576 in forum New To Java
    Replies: 5
    Last Post: 03-14-2010, 01:13 AM
  3. [SOLVED] Decimal Places - Is this possible?
    By dbashby in forum New To Java
    Replies: 4
    Last Post: 04-08-2009, 07:49 PM
  4. numbers with two decimal places
    By little_polarbear in forum New To Java
    Replies: 8
    Last Post: 08-27-2008, 11:04 PM
  5. Capping decimal places
    By Rageagainst20 in forum New To Java
    Replies: 1
    Last Post: 12-20-2007, 09:28 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
  •