Sha256: 741fb09f82e60a18f8bba6b3793d959ccd5a6c83d93806696751fc5b7e8739f9

Contents?: true

Size: 709 Bytes

Versions: 13

Compression:

Stored size: 709 Bytes

Contents

module HasAccounts #:nodoc:
  module CoreExtensions #:nodoc:
    module Rounding
      # Rounds the float according to currency rules.
      # Currently targeted to Swiss Francs (CHF), usable
      # for all currencies having 0.05 as smallest unit.
      #
      #   x = 1.337
      #   x.round    # => 1.35
      def currency_round
        if self.nil?
          return 0.0
        else
          return (self * 20).round / 20.0
        end
      end
    end
    
    module BigDecimal
      module Rounding
        def currency_round
          if self.nil?
            return BigDecimal.new("0")
          else
            return (self * 20).round / 20
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
has_accounts-0.8.2 lib/has_accounts/core_ext/rounding.rb~
has_accounts-0.8.1 lib/has_accounts/core_ext/rounding.rb~
has_accounts-0.8.0 lib/has_accounts/core_ext/rounding.rb~
has_accounts-0.7.1 lib/has_accounts/core_ext/rounding.rb~
has_accounts-0.7.0 lib/has_accounts/core_ext/rounding.rb~
has_accounts-0.6.1 lib/has_accounts/core_ext/rounding.rb~
has_accounts-0.6.0 lib/has_accounts/core_ext/rounding.rb~
has_accounts-0.5.0 lib/has_accounts/core_ext/rounding.rb~
has_accounts-0.4.1 lib/has_accounts/core_ext/rounding.rb~
has_accounts-0.4.0 lib/has_accounts/core_ext/rounding.rb~
has_accounts-0.3.0 lib/has_accounts/core_ext/rounding.rb~
has_accounts-0.2.2 lib/has_accounts/core_ext/rounding.rb~
has_accounts-0.2.1 lib/has_accounts/core_ext/rounding.rb~