I have a distance as a float and I\'m looking for a way to format it nicely for human readers. Ideally, I\'d like it to change from m to km as it gets bigger, and to round the n
iOS 7 and OS X 10.9 introduced MKDistanceFormatter for formatting distances:
Code Example:
double myDistance = 21837.0f;
MKDistanceFormatter *df = [[MKDistanceFormatter alloc]init];
df.unitStyle = MKDistanceFormatterUnitStyleAbbreviated;
NSLog(@"myDistance is %@", [df stringFromDistance: myDistance]);
Update:
It seems that MKDistanceFormatter is rounding the input value somehow. E.g. when I set myDistance to 111.0 I get "100 m".