Does Ruby have any number formatting classes?

后端 未结 4 865
我在风中等你
我在风中等你 2020-12-18 17:53

Does Ruby have any Formatter classes or methods that can be used to format numbers for things like currency, etc., or are there any gems that do this, or do you have to writ

4条回答
  •  庸人自扰
    2020-12-18 18:18

    Ruby has all the standard print formatters, available either via printf, sprintf or using 'formatstring' % [var1, ...].

    >> '%.2f' % 3.14159 #=> "3.14"
    >> '%4s %-4s' % ['foo', 'bar'] #=> " foo bar "
    

提交回复
热议问题