开发者

Rails, When displaying a number, if 0 or under 10, always show two 00 zeos

开发者 https://www.devze.com 2023-01-26 19:45 出处:网络
I have query which returns a count. Regardless of whether is 0 or 4 (anything under 10, I always want the number to display like so:开发者_开发百科

I have query which returns a count. Regardless of whether is 0 or 4 (anything under 10, I always want the number to display like so:开发者_开发百科

If / Display:
0 / 00
2 / 02
12 / 12

IE always with the 00 place holder. Is there a helper method for this or is this a custom job?


Try this:

"%02d" % my_int

For documentation, see here.

0

精彩评论

暂无评论...
验证码 换一张
取 消