# Thread: Problem with division using doubles

1. Member
Join Date
Oct 2009
Posts
2
Rep Power
0

## Problem with division using doubles

Hey guys,
I'm working on a project in my beginner Java class and the only thing that is not working is division. I feel like it might just be something really simple I can't see, but every time I divide two numbers and assign it to a double, the answer truncates itself like an int and loses all values that aren't whole numbers. Here for example, is a program that converts fahrenheit to celsius:

Java Code:
```public class test
{
public static void main(String [] args)
{
double c;
double boil = 212;
String output;

c = (boil - 32) * (5/9);
output = boil + " in Fahrenheit is " + c + " in Celsius.";
System.out.println(output);
}
}```
This outputs c = 0 for me because the problem is the 5/9. Instead of being .556, it truncates and is 0.

This code below doe the same thing except instead of using (5/9), I assign the values 5 and 9 to two double vars called one and two, divide, and get the correct answer.
Java Code:
```public class test
{
public static void main(String [] args)
{
double one, two;
double c;
double boil = 212;
String output;

one = 5;
two = 9;
c = (boil - 32) * (one / two);
output = boil + " in Fahrenheit is " + c + " in Celsius.";
System.out.println(output);
}
}```
Please help me out! I worked on this for 4 hours last night and couldn't figure out what is wrong

2. Member
Join Date
Oct 2009
Posts
2
Rep Power
0
Oh my god thanks dude. You're a savior

3. Originally Posted by chrismanahan
Oh my god thanks dude. You're a savior
No, I'm just one who has tripped over this problem himself in the past. Good luck.