can someone give me an idea how I limit the decimals in the output of this code:

/**
 * @(#)Text1.java
 *
 *
 * @author Bryan Mark
 * @version 1.00 2012/8/4
 */


import java.io.*;
public class Converter 
{
    public static void main(String[] args)throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        double farenheit, celsius;

        System.out.println("Enter a value for Farenheit: ");
        farenheit = Double.parseDouble(br.readLine());
        celsius = (5.0/9) * farenheit - 32;
        System.out.println("Farenheit " + farenheit + " = " + celsius + " Celsius");

    }
}

this is a sample output..

Enter a value for Farenheit:
29.5
Farenheit 29.5 = -15.61111111111111 Celsius

Recommended Answers

All 2 Replies

you could format the output similar to C like so:

System.out.printf("Farenheit %.2f = %.2f Celsius",farenheit,celsius);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.