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: Printing out to two decimal places

  1. #1
    Junior Member
    Join Date
    May 2018
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Printing out to two decimal places

    println.jpg

    Hi, the code in the picture needs to print out to two decimal places, but I cant get it to perform this action, does anyone know the syntax for this?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Printing out to two decimal places

    Look at the API doc for the Formatter class. It shows how to code a format String that can be used with the printf method to control the number of decimal places.

    Copying and pasting code or the contents of a console window here is better that using images which are often hard to read and don't allow copying of its contents to include in a response.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Formatting answers to 2 decimal places
    By Cal S. in forum What's Wrong With My Code?
    Replies: 27
    Last Post: September 13th, 2014, 03:17 AM
  2. How do I get my answers to out with 2 decimal places?
    By dunnage888 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 8th, 2012, 12:23 PM
  3. New to Java Need 2 decimal places, please :). Here is my code
    By Charyl in forum Member Introductions
    Replies: 2
    Last Post: June 28th, 2011, 03:06 AM
  4. float to 2 decimal places
    By fh84 in forum Java Theory & Questions
    Replies: 3
    Last Post: November 25th, 2009, 11:27 AM
  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, 03:17 AM