如何填充前面的0的整数? [英] How to pad the integer withe preceeding 0?

查看:305
本文介绍了如何填充前面的0的整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像6或65的整数值。如果这个值是单个数字,我想把它显示为06,如果它是65,那么就是这样(仅限65)。我已经搜索到的NSNumberFormatter类的iPhone,但没有得到什么确切的。任何人都可以帮助我吗?



在此先感谢!!

使用%02d格式说明符,例如

  NSLog(@%02d,number); 

这将输出至少有2个字符长度的整数,如果需要的话,输出将用前缀零填充

I am having an integer value like 6 or 65 . If the value is single digit I want to display it like 06 and if it is 65 then as it is ( 65 only ) . I have searched into the NSNumberFormatter class of iphone but not getting what to do exactly . Can any one help me in this ?

Thanks in advance !!

解决方案

Use %02d format specifier, e.g.

NSLog(@"%02d", number);

That will output integer number with at least 2 characters length and output will be padded with leading zeroes if required

这篇关于如何填充前面的0的整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆