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.


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

Results 1 to 2 of 2

Thread: How to format?

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Thanked 0 Times in 0 Posts

    Default How to format?

    Here is the code:

    import java.util.Scanner;
    public class Problem2 {
        public static void main (String []args){
     // Scanner
            Scanner scan = new Scanner(System.in);
     // Declorations
            double kilograms = 1;
    // For loop
          for (int i = 1; i <= 199; i += 2) {
     System.out.println(i + "                " + i * 2.2);

    The answers give me two columns, but the problem is sometimes there are 10 zeros after the decimal so for the third answer it is 6.6000000000 etc. I just want to use one character after the decimal and I don't know how. I have tried the printf and using %d,f etc but that didn't work :/

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 833 Times in 772 Posts
    Blog Entries

    Default Re: How to format?

    How to Format a double to 2 decimal places

Similar Threads

  1. [SOLVED] For loop-ing decimal format
    By Harj in forum Loops & Control Statements
    Replies: 10
    Last Post: October 1st, 2010, 05:47 PM
  2. [SOLVED] Help with code, Says number is NaN and i cant format it
    By NewGuy in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 4th, 2010, 08:28 PM
  3. Format some text with Java
    By vampire in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 18th, 2010, 11:30 AM
  4. Sting format give more truble
    By ahmethbaai in forum Java Theory & Questions
    Replies: 1
    Last Post: December 17th, 2009, 01:19 PM
  5. help with text format codes
    By vanchan09 in forum Java Theory & Questions
    Replies: 1
    Last Post: November 15th, 2009, 04:12 PM