NSLog(@"%02ld",2);
NSLog(@"%0.2f",0.2656);
NSLog(@"%0.2f",0.2646);
注意的是%0.2f 是会对数字进行一个四舍五入
2021-01-20 14:57:28.506 App[4010:98217] 02
2021-01-20 14:57:28.507 App[4010:98217] 0.27
2021-01-20 14:57:28.507 App[4010:98217] 0.26
NSLog(@"%02ld",2);
NSLog(@"%0.2f",0.2656);
NSLog(@"%0.2f",0.2646);
注意的是%0.2f 是会对数字进行一个四舍五入
2021-01-20 14:57:28.506 App[4010:98217] 02
2021-01-20 14:57:28.507 App[4010:98217] 0.27
2021-01-20 14:57:28.507 App[4010:98217] 0.26
本文标题:iOS 让数字保持两位数格式
本文链接:https://www.haomeiwen.com/subject/rrhfkrtx.html
网友评论