double knots = currentLocation.speed*1.943844492;
NSString *speed = [NSString stringWithFormat:@"%03.1f", knots];
这会产生一个没有前导零的普通单十进制 float 。 目的是获得最多 3 个前导数字和一位小数。
最佳答案
3
是包括小数点和小数位在内的总长度。将 3
更改为 5
,你应该得到你想要的:
NSString *speed = [NSString stringWithFormat:@"%05.1f", knots];
关于ios - 使用零填充 float 的 stringWitFormat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24538939/