Conversion Fahrenheit to celsius programmatically
Posted
by
Doom
on Stack Overflow
See other posts from Stack Overflow
or by Doom
Published on 2012-09-13T09:05:02Z
Indexed on
2012/09/13
9:38 UTC
Read the original article
Hit count: 305
In my project, want to show the weather in fahrenheit first, then if the user wants clickes on conversion, needs to show the weather in celsius. My code is
NSNumber *metric = [[NSUserDefaults standardUserDefaults] objectForKey:@"metric"];
NSLog(@"Metric is %@", metric);
CGFloat aFloat = [speed floatValue];
CGFloat tFloat = [temperature floatValue];
CGFloat tempFloat = (tFloat-30)/2;
NSNumber * p_Number = [NSNumber numberWithFloat:tempFloat];
//Convert mph to kmph
if ([metric boolValue]) {
[windValueLabel setText:[NSString stringWithFormat:@"%.2f kmph", aFloat * 1.6] ];
temperatureLabel.text = [NSString stringWithFormat:@"%@", p_Number];
}
else{
[windValueLabel setText:[NSString stringWithFormat:@"%.2f mph", aFloat / 1.6]];
temperatureLabel.text = [NSString stringWithFormat:@"%@", temperature];
}
When u start the app, its working and showing temperature in fahrenheit, but crashes at celsius man... is that the current conversion. help me out guys
© Stack Overflow or respective owner