Hi all,
I'm trying to create a unit converter, one of the things it does is temperature conversion.
So the formula for farenheit is f=(c*(9/5))+32
If I run my code with a value of 12, i get 44, however when I do it in spotlight calculator or in the apple converter I get 53.6.
My problem, I have now worked out after splitting up the formula and breakpointing it, is that it says 9/5 = 1, whereas it clearly equals 1.8. For some reason my floats are being rounded (or floored in this case)?? - Should I be using a double or something??
here is my method (split up for debug purposes):
Code:
- (float)celsiusToFarenheit:(float)c {
float divider = 9/5;
float firstPart = c*divider;
float ans = firstPart+32;
return ans;
}
Thanks in advance,
Alex
EDIT: Sorry have now solved it requires me to put 9.0/5.0 instead of 9/5