Module: MidwireCommon::NumberBehavior
Overview
Common number behavior
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
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 |