Froze rails gems
[depot.git] / vendor / rails / activesupport / lib / active_support / core_ext / float / rounding.rb
1 module ActiveSupport #:nodoc:
2 module CoreExtensions #:nodoc:
3 module Float #:nodoc:
4 module Rounding
5 def self.included(base) #:nodoc:
6 base.class_eval do
7 alias_method :round_without_precision, :round
8 alias_method :round, :round_with_precision
9 end
10 end
11
12 # Rounds the float with the specified precision.
13 #
14 # x = 1.337
15 # x.round # => 1
16 # x.round(1) # => 1.3
17 # x.round(2) # => 1.34
18 def round_with_precision(precision = nil)
19 precision.nil? ? round_without_precision : (self * (10 ** precision)).round / (10 ** precision).to_f
20 end
21 end
22 end
23 end
24 end