riji riji - 9 months ago 30
Objective-C Question

How to convert and print given kelvin value to celsius on another label in objective c

On a webservice program,i fetched temperature value from an API and its in kelvin value....i want to convert that to celsius and print to another label in same page along with that kevin value... As a beginner i don't know much how to do..please help

lbl1.text=[dic retrieveForPath:@"current.city.@name"];

lbl2.text=[dic retrieveForPath:@"current.city.coord.@lon"];

lbl3.text=[dic retrieveForPath:@"current.temperature.@value"];

here on 'lbl3 ,i printed temperature in kelvin.....and how to convert and print that to another label by doing this equation T(°C) = T(K) - 273.15


Assuming that you have a lbl4 object, this will display the data with 2 decimal places, e.g. 12.51C

float centigrade = [[dic retrieveForPath:@"current.temperature.@value"] floatValue] - 273.15;
lbl4.text = [NSString stringWithFormat:@"%.2fC", centigrade];