码迷,mamicode.com
首页 > 其他好文 > 详细

ruby 格式化字符串 浮点数

时间:2014-09-23 15:40:04      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   使用   ar   strong   for   2014   sp   

在ruby中使用format(或 "%")来格式化string.

例子

"Number is %d" % 12     # Number is 12
format("Number is %d" , 12)    # Number is 12

"Number is %d, type  is %s"   %  [12, "cat"]     
# Number is 12, type is cat
format("Number is %d, type  is %s" ,[12, "cat"] )    
# Number is 12, type is cat

"[%10s]"  %  "cat"                #[       cat]
format("[%10s]", "cat")        #[       cat]

"[%-10s]"  %   "cat"              #[cat       ]
format("[%-10s]","cat")        #[cat       ]

原文链接:http://www.dotnetperls.com/format

ruby 格式化字符串 浮点数

标签:style   blog   http   使用   ar   strong   for   2014   sp   

原文地址:http://blog.csdn.net/dazhi_100/article/details/39496055

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!