Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 int 并将其转换为 NSString ,如下所示:
NSString *myStr = [NSString stringWithFormat:@"%d",myInt];
myInt 的范围从 0 到 99999。我想要的是将 myStr 作为 5 位数字。
例如:00072 或 09856 或 00002
谢谢你。
使用%05d格式说明符以填充零:
%05d
NSString *myStr = [NSString stringWithFormat:@"%05d", myInt];
维基百科的解释。