Hello There!
I have a method that receives a number in a NSString format.
I wish to convert this string to a double which I can use to calculate a temperature.
Here's my method.
NSString *stringTemp = text; // text is a NSString
NSLog(@"%@",stringTemp); // used for debugging
double tempDouble = [stringTemp doubleValue];
NSLog(@"%f",tempDouble); // used for debugging
Please note I put the NSLog
commands here just to see if the number was correct. The latter NSLog
returns a value of 82.000000
etc. (constantly changes as it's a temperature).
Next I wanted to use this double
and convert it to a Celsius value. To do so, I did this:
double celsiusTemp = (5 / 9) * (tempDouble - 32);
Doing this: NSLog(@"%d", celsiusTemp);
, or this: NSLog(@"%f", celsiusTemp);
both give me a value of 0 in the console. Is there any reason why this would be happening? Have I made a stupid mistake somewhere?
Thank you for your help!