# really quick question for beginner

• 06-17-2010, 03:51 AM
its_crawford
really quick question for beginner
hey there, im making a little program that converts celcius to farenheit blah blah not important

heres the situation:

celcius = c
farenheit = f
(bot c and f are doubles)

c = (5/9) * (f-32)

weird thing is using that equation doesnt work and my value for C will be zero

i know it a problem with 5/9 because if i use someone like 10/5 itll work just fine. so whats the problem with 5/9? is division whacky in java or something?
• 06-17-2010, 04:02 AM
Fubarable
You are stumbling against int division. You see an int divided by an int will result in an int, with rounding and all. Convert one to a double:

c = (5.0/9.0) * (f-32)
• 06-17-2010, 04:06 AM
its_crawford
mmmother F! so simple! thanks!
• 06-17-2010, 04:09 AM
Fubarable
You're quite welcome. Welcome to the forum by the way!
• 06-17-2010, 04:14 AM
Eranga
Quote:

Originally Posted by Fubarable
You are stumbling against int division. You see an int divided by an int will result in an int, with rounding and all. Convert one to a double:

c = (5.0/9.0) * (f-32)

Assign 5/9 into a local int variable and see what's the result. Situations like this you can do that.