Class: Fixnum
- Inherits:
-
Object
- Object
- Fixnum
- Defined in:
- lib/midwire_common/fixnum.rb
Instance Method Summary collapse
-
#commify ⇒ Object
Format a number with commas and a decimal point rubocop:disable Style/PerlBackrefs.
Instance Method Details
#commify ⇒ Object
Format a number with commas and a decimal point rubocop:disable Style/PerlBackrefs
4 5 6 7 8 9 10 |
# File 'lib/midwire_common/fixnum.rb', line 4 def commify to_s =~ /([^\.]*)(\..*)?/ int, dec = $1.reverse, $2 ? $2 : '' while int.gsub!(/(,|\.|^)(\d{3})(\d)/, '\1\2,\3') end int.reverse + dec end |