I am facing this silly problem :
I want to use a float value for some comparison...Unfortunately the value I get from the slider is something like 14.545645646 ... and the other values I have are like 5.2, 54.9 etc....
I am not very sure what to do here .... is there a way to truncate after 2decimal digits 开发者_开发百科?
Please let me know. Thanks.
Multiply by 100, cast to an int, and divide by 100.0?
Above solution don't work. It get same value.
It is lot easier to use the formatter %.2f
float abc = 0.4343322 NSLog(@"Formatted value : %.2f", abc);
NSLog(@"Distance i meters: %.02f", [itemloc distanceFromLocation:current]/1000);
精彩评论