Module: NumericRubyExtended

Included in:
BigDecimal, Complex, Float, Integer, Rational
Defined in:
lib/ruby_extended/number.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ruby_extended/number.rb', line 4

def self.included(base)
  base.class_eval do

    def no_zeros
      self.to_f.to_s.gsub(/\.0+$/, '')
    end

    def to_money
      '%.2f' % self.to_f
    end

    def percent_of(percent, options = {})
      result = (self.to_f / 100.to_f * percent.to_f)
      options[:decimal] ? result : result.to_i
    end

    def get_percent_from(value, options = {})
      result = (self.to_f / value.to_f * 100)
      options[:decimal] ? result : result.to_i
    end

  end
end