Conversion Fahrenheit to celsius programmatically
- by Doom
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