Computing.Net > Forums > Programming > Decimal Places

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Decimal Places

Reply to Message Icon

Name: StupidProgrammer
Date: July 15, 2009 at 10:48:11 Pacific
OS: Windows XP
Subcategory: Java
Comment:

okay well i figured out this much with some help from my friend. My issue is to make it so that the answer will give me a few decimal places. ie if the answer is 89.6 my current program is giving me 89.

import java.util.*;

public class WWWTempConvert
{

public static void main(String[] args)
{
System.out.println("I will convert from either degrees Celsius to Fahrenheit or from degrees Fahrenheit to Celsius.");
System.out.println("Please enter a number with either C or c for Celsius or F or f for Fahrenheit:");
System.out.println("If you wish to quit please press Q or q");

Scanner keyboard = new Scanner(System.in);
int num;
String unit;
String prompt;

while (keyboard.hasNext()) {
prompt = keyboard.next();

if (prompt.equalsIgnoreCase("Q")) {
System.out.println("Exiting");
System.exit(0);
}
unit = keyboard.next();
num = Integer.parseInt(prompt);

if (unit.equalsIgnoreCase("C")) {
System.out.println("The value in Fahrenheit is:");
System.out.println(((9*num)/5 + 32)+" F");
}

else if (unit.equalsIgnoreCase("F")) {
System.out.println("The value in Celsius is:");
System.out.println(((5*(num-32)/9))+" C");
} else
System.out.println("Error.");

System.out.println("Enter next value or enter q or Q to quit: ");
}


}
}



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: July 22, 2009 at 15:04:55 Pacific
Reply:

Hi

I'm not familiar with Java, but if it can handle decimals try changing one of the numbers to decimal, maybe it treats your sum as integer because your numbers are integers.
Try changing one of them or all to decimal.

System.out.println(((9.0*num)/5.0 + 32.0)+" F");


0
Reply to Message Icon

Related Posts

See More


bat file Using a Macro to copy and...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Decimal Places

Decimal places in vb6 www.computing.net/answers/programming/decimal-places-in-vb6/13248.html

Delphi convert to 2 decimal places www.computing.net/answers/programming/delphi-convert-to-2-decimal-places/9810.html

getting decimal places vb6 formula www.computing.net/answers/programming/getting-decimal-places-vb6-formula/12754.html