I try to divide 9/5 for the Celsius to Fahrenheit method but the answer is 1. When doing this in an online compiler like:
double T = 9/5;
The answer when printing T = 1.8
Could someone give me a hint?

# 9/5 = 1..?

Comments(4)

- Popular
- New
- Old

You must be signed in to leave a comment

PeterLevel 4 , Enschede

7 September, 19:44

@Lotia
I misunderstood you. Thought you meant just double .. but you probably meant 9.0/5.0.
Thanks

0

LotiaLevel 11 , Gdańsk

7 September, 21:11

@Peter
That's right. One of this numbers (9 or 5) or both must be a double type (notation with dot).
If you try either 9.0/5 or 9/5.0 or 9.0/5.0 then the result will be 1.8 because you will be using floating-point division.
If you try division 9/5 then the result will be 1

+1

PeterLevel 4 , Enschede

7 September, 19:39

That is what I tried but that does not seem to work...

0

LotiaLevel 11 , Gdańsk

7 September, 18:49

Use double type instead of Integer because double is floating point type and Integer not.
When divide 9/5 (int types) result is 1 because is division without change
When divide double types (at least one of this variables must be double) you have result 1.8
I hope I answered Your question ☺️

+1