ruby 葡萄定制格式

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 葡萄定制格式相关的知识,希望对你有一定的参考价值。

Grape::Entity.format_with :utc do |date|
  date.strftime('%Y年%m月%d日 %H:%M') if date
end

Grape::Entity.format_with :date do |date|
  date.strftime('%Y年%m月%d日') if date
end
Grape::Entity.format_with :datetime do |date|
  date.strftime('%Y年%m月%d日 %H:%M:%S') if date
end
Grape::Entity.format_with :rmb do |money, options|
  ActiveSupport::NumberHelper.number_to_currency(money, unit: '元') if money
end
Grape::Entity.format_with :rmb_p0 do |money, options|
  ActiveSupport::NumberHelper.number_to_currency(money, unit: '元', precision: 0) if money
end
Grape::Entity.format_with :round do |money|
  ActiveSupport::NumberHelper.number_to_rounded(money, precision: 2).to_f if money
end

以上是关于ruby 葡萄定制格式的主要内容,如果未能解决你的问题,请参考以下文章