开发者

Using number_with_precision on controller in rails3

开发者 https://www.devze.com 2023-01-30 01:06 出处:网络
I want to use this helper method on 开发者_运维知识库controller. Any way to achieve this?Probably not a great idea, but if you must, include the helper like so:

I want to use this helper method on 开发者_运维知识库controller. Any way to achieve this?


Probably not a great idea, but if you must, include the helper like so:

class WhateverController
  include ActionView::Helpers::NumberHelper

  def show
    render :text => number_with_precision(2342.234, :precision => 2)
  end

end


A much better way to control number precision is rails controllers is to use sprintf

"%.2f" % 2342.234 => "2342.23"
"%.6f" % 2342.234 => "2342.234000"
0

精彩评论

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