开发者

ROR: Zero-padding removed upon database query

Is there anyway to make .find not remove zeropadding on the values it pulls back from the database?

ie. I have zipcodes in a database and some of them are shorter than 5 characters. I am zeropadding thme back to 5 characters in the database, so I end up with "00210" for 开发者_如何学Goexample. However, this value just becomes "210" in my array.

I know I can use "%05d" % value to zeropad it when it's going back into the views... but I'd rather not have to zeropad it on the way out like that.


A Fixnum (the Ruby type you're dealing with) only cares about value. my_var = 00000001 in ruby sets my_var to 1, and outputting it as a string results in "1". If you want to format it differently, you'll have to rely on string functionality.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜