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: double doesn't show decimal places

  1. #1
    Junior Member Gugubo's Avatar
    Join Date
    Jul 2013
    Posts
    24
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default double doesn't show decimal places

    This:

    double test = 100/3;
    System.out.print(test);
    gives as output 33.0. Isn't it supposed to output 33.3333...?
    Am I missing something?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,320
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: double doesn't show decimal places

    The expression to the right of the = does integer math: 100/3 gives 33 and that is converted to a double.
    To do floating pt math change one of the numbers to a double: 100.0/3
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How to set value of double to 2 decimal places
    By tonynsx in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 20th, 2013, 03:15 PM
  2. 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, 04:08 PM
  3. Java program to format a double value to 2 decimal places
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 3
    Last Post: December 4th, 2010, 04:08 PM
  4. Limiting decimal places in a double
    By darek9576 in forum Object Oriented Programming
    Replies: 2
    Last Post: March 14th, 2010, 12:27 PM
  5. [SOLVED] How to use decimal place when formatting an output?
    By napenthia in forum Java Theory & Questions
    Replies: 2
    Last Post: April 27th, 2009, 04:17 AM