Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: URGENT - Format a double?

  1. #1
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default URGENT - Format a double?

    ok its 1:36AM and ive got to finish this last tiny thing.

    So ive done the calculations, now the times are 9AM - 5PM where u enter an int in the apropreite time/day.

    Clicking calculate will show the weekly average which is a double

    When im finding the average of all the weekly averages put together it displays for example:

    13.666666666666666

    how do i format it to only show 13.6 ?

    code:
    // WEEK ROW 10 AVERAGE
    	double totalJ = weekA + weekB + weekC + weekD + weekE + weekF + weekG + weekH + weekI;
    	txtBox[69].setText(Double.toString(totalJ));
     
    	// WEEK ROW 11 AVERAGE
     
    	double doubleK = totalJ / 9;
    	txtBox[76].setText(Double.toString(doubleK));

    ok thanks


  2. #2
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: URGENT - Format a double?

    meh fixed it the fix for this was:

    // WEEK ROW 11 AVERAGE
     
    	double doubleK = totalJ / 9;
    	 DecimalFormat decimalFormat = new DecimalFormat("#.##");
    	txtBox[76].setText(decimalFormat.format(doubleK));

    Thread marked as solved.

Similar Threads

  1. int / double validation
    By exnuke1972 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 20th, 2011, 04:08 PM
  2. PLEASE HELP ME with double buffer
    By DouboC in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2011, 04:32 PM
  3. Java program to format a double value to 2 decimal places
    By JavaPF in forum Java Programming Tutorials
    Replies: 3
    Last Post: December 4th, 2010, 03:08 PM
  4. How to format?
    By maximus20895 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 15th, 2010, 01:07 PM
  5. Double Buffering
    By Ganezan in forum Java Theory & Questions
    Replies: 2
    Last Post: November 20th, 2009, 02:51 AM