Results 1 to 5 of 5
  1. #1
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question [SOLVED] Decimal Places - Is this possible?

    my program uses

    Java Code:
    DecimalFormat bodymass = new DecimalFormat("#0.0");
    So I have 1 decimal place, however I have another calculation within my program that I want to calculate to 2 decimal places.

    Java Code:
    DecimalFormat bodymass = new DecimalFormat("#0.00");
    Is this possible?

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

    Default

    I would use two separate DecimalFormat variables here, then use whichever one is needed at the time of its need. YMMV.

  3. #3
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question

    I just forgot to change the variable in the code posted

    well the
    Java Code:
    DecimalFormat bodymass = new DecimalFormat("#0.0");
    this is in the main body of the program

    the second decimal I want within

    Java Code:
    private void cmdConvertActionPerformed(java.awt.event.ActionEvent evt) {
    but i want it to be to 2 places

    Java Code:
    DecimalFormat measurement = new DecimalFormat("#0.0");
    So it is possible?

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

    Default

    It should work and if it doesn't it likely has nothing to do with using different decimal formatters. Have you tried it? What happens when you do?

  5. #5
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

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. Replies: 4
    Last Post: 03-03-2009, 12:43 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
  •