开发者

Ruby formatting for ordinals: '1' as '1st', '2' as '2nd' etc

开发者 https://www.devze.com 2023-01-08 23:40 出处:网络
Is anything baked into ruby or r开发者_如何学运维ails to handle formatting for ordinals:\'1\' as \'1st\', \'2\' as \'2nd\', etc.?Looks like you are looking for ordinalize:

Is anything baked into ruby or r开发者_如何学运维ails to handle formatting for ordinals: '1' as '1st', '2' as '2nd', etc.?


Looks like you are looking for ordinalize:

The Ruby on Rails framework is chock full of interesting little nuggets. Ordinalize is a number extension that returns the corresponding ordinal number as a string. For instance, 1.ordinalize returns “1st” and 22.ordinalize return “22nd”.

Example:

place = 3 puts "You are currently in #{place.ordinalize} place."

Result:

You are currently in 3rd place.

0

精彩评论

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