Objective c string formatter for distances
- by nevan
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 number nicely. Converting to miles would be a bonus. I'm sure many people have had a need for one of these and I'm hoping that there's some code floating around somewhere.
Here's how I'd like the formats:
0-100m: 47m (as a whole number)
100-1000m: 325m or 320m (round to the nearest 5 or 10 meters)
1000-10000m: 1.2km (round to nearest with one decimal place)
10000m +: 21km
If there's no code available, how can I write my own formatter?
Thanks