instance method
round_with_precision
Ruby on Rails 2.2.3
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
round_with_precision(precision = nil)
Rounds the float with the specified precision.
x = 1.337 x.round # => 1 x.round(1) # => 1.3 x.round(2) # => 1.34
Parameters
-
precisionopt = nil
Source
# File activesupport/lib/active_support/core_ext/float/rounding.rb, line 18
def round_with_precision(precision = nil)
precision.nil? ? round_without_precision : (self * (10 ** precision)).round / (10 ** precision).to_f
end
Defined in activesupport/lib/active_support/core_ext/float/rounding.rb line 18
· View on GitHub
· Improve this page
· Find usages on GitHub