Formats a number with the specified level of precision (e.g., 112.32 has a precision of 2). The default level of precision is 3.
Examples
number_with_precision(111.2345) # => 111.235 number_with_precision(111.2345, 2) # => 111.24 number_with_precision(13, 5) # => 13.00000 number_with_precision(389.32314, 0) # => 389
Source Code
# File action_view/helpers/number_helper.rb, line 143 def number_with_precision(number, precision=3) "%01.#{precision}f" % number rescue number end
<code/>and<pre/>for code samples.