Results 1 to 5 of 5
  1. #1
    mcollins is offline Member
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

    Default How to display an int or a double with two decimal places

    Hello,

    I am wanting to display an int or a double with 2 decimal places... The program is working with money (dollars $)... maybe there is a better way of handling money in a variable?

    Any help/suggestions would be great!

    Thanks.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    There is a better way. I'd recommend that you look into using a NumberFormat object, in particular, a currency instance. Have a look at the API for details.

  3. #3
    mcollins is offline Member
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

    Default

    I am a little confine to basic Java, so I'm guessing API is out of hte question for me... Any other ideas?

  4. #4
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    NumberFormat is part of java. API is a common term, "application programming interface", and means "the gob of gue in the package I just told you about". Google for 'java 6 api', and watch the world unfold.

  5. #5
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default

    Basic Java is made up of APIs. Here's the link to the Java 6 API specification:

    Java Platform SE 6

    In particular, this the link to the method Fubarable was refering to:

    NumberFormat (Java Platform SE 6)

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

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. rounding double to two decimal places
    By javaMike in forum Advanced Java
    Replies: 15
    Last Post: 03-10-2010, 12:04 AM
  3. get percentage formatting to display 2 decimal places
    By gotenks05 in forum New To Java
    Replies: 5
    Last Post: 03-03-2009, 04:57 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
  •