Class: Numeric
Overview
:nodoc:
Constant Summary collapse
- TO_DECIMAL_SEPERATOR =
:comma
Instance Method Summary collapse
- #nearest(factor = 10) ⇒ Object
- #to_s_decimal(decimal_seperator = TO_DECIMAL_SEPERATOR) ⇒ Object
- #zero_padded(padding = 3) ⇒ Object
Instance Method Details
#nearest(factor = 10) ⇒ Object
52 53 54 |
# File 'lib/active_form/core_extensions.rb', line 52 def nearest(factor = 10) (self.to_f/factor.to_f).round * factor end |
#to_s_decimal(decimal_seperator = TO_DECIMAL_SEPERATOR) ⇒ Object
60 61 62 63 64 |
# File 'lib/active_form/core_extensions.rb', line 60 def to_s_decimal(decimal_seperator = TO_DECIMAL_SEPERATOR) str = self.to_s str.gsub!(/\.(\d+)(\s|$)/, ',\1') if (decimal_seperator == :comma && str =~ /\.(\d+)(\s|$)/) str end |
#zero_padded(padding = 3) ⇒ Object
56 57 58 |
# File 'lib/active_form/core_extensions.rb', line 56 def zero_padded(padding = 3) return "%0#{padding}d" % self.abs end |