Objective c string formatter for distances

后端 未结 7 1825
借酒劲吻你
借酒劲吻你 2021-02-02 01:45

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

7条回答
  •  醉酒成梦
    2021-02-02 02:32

    found this today asking the same question....going with :

     NSString *rvalue;
        if (value > 1000) {
            rvalue = [NSString stringWithFormat:@"%.02f km",value];
        }else {
            rvalue = [NSString stringWithFormat:@"%.02f m",value];
        }
    

    could wrap this in a method, if need be

提交回复
热议问题