Module: MidwireCommon::NumberBehavior

Included in:
Fixnum, Float
Defined in:
lib/midwire_common/number_behavior.rb

Overview

Common number behavior

Instance Method Summary collapse

Instance Method Details

#commifyObject

Format a number with commas and a decimal point rubocop:disable Style/PerlBackrefs



6
7
8
9
10
11
12
13
# File 'lib/midwire_common/number_behavior.rb', line 6

def commify
  to_s =~ /([^\.]*)(\..*)?/
  int = $1.reverse
  dec = $2 ? $2 : ''
  while int.gsub!(/(,|\.|^)(\d{3})(\d)/, '\1\2,\3')
  end
  int.reverse + dec
end