Module: HasAccounts::CoreExtensions::Rounding

Included in:
Fixnum, Float
Defined in:
lib/has_accounts/core_ext/rounding.rb

Instance Method Summary collapse

Instance Method Details

#currency_roundObject

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


10
11
12
13
14
15
16
# File 'lib/has_accounts/core_ext/rounding.rb', line 10

def currency_round
  if self.nil?
    return 0.0
  else
    return (self * 20).round / 20.0
  end
end