Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/gf_utility/numeric.rb
Instance Method Summary collapse
-
#with_separator(separator = ',', length = 3) ⇒ Object
ritorna una stringa con le migliaia serparate da <separator> es.: 100000 -> 1.000.000.
Instance Method Details
#with_separator(separator = ',', length = 3) ⇒ Object
ritorna una stringa con le migliaia serparate da <separator> es.: 100000 -> 1.000.000
9 10 11 12 13 14 15 16 |
# File 'lib/gf_utility/numeric.rb', line 9 def with_separator( separator = ',', length = 3 ) splitter = Regexp.compile "(\\d{#{length}})" before, after = self.to_s.split('.') before = before.reverse.gsub splitter, '\1' + separator str = "#{ before.chomp( separator ).reverse }" str += ".#{ after }" if after return str end |