module NumericRubyExtended
Public Class Methods
included(base)
click to toggle source
# 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 percent_in(value, options = {}) result = (self.to_f / value.to_f * 100) options[:decimal] ? result : result.to_i end end end
Public Instance Methods
no_zeros()
click to toggle source
# File lib/ruby_extended/number.rb, line 7 def no_zeros self.to_f.to_s.gsub(/\.0+$/, '') end
percent_in(value, options = {})
click to toggle source
# File lib/ruby_extended/number.rb, line 20 def percent_in(value, options = {}) result = (self.to_f / value.to_f * 100) options[:decimal] ? result : result.to_i end
percent_of(percent, options = {})
click to toggle source
# File lib/ruby_extended/number.rb, line 15 def percent_of(percent, options = {}) result = (self.to_f / 100.to_f * percent.to_f) options[:decimal] ? result : result.to_i end
to_money()
click to toggle source
# File lib/ruby_extended/number.rb, line 11 def to_money '%.2f' % self.to_f end