Class: Float

Inherits:
Object
  • Object
show all
Defined in:
lib/midwire_common/float.rb

Instance Method Summary collapse

Instance Method Details

#commifyObject

Format a number with commas and a decimal point



3
4
5
6
7
8
9
# File 'lib/midwire_common/float.rb', line 3

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