Class: BigDecimal

Inherits:
Object show all
Defined in:
lib/kiss/model.rb

Instance Method Summary collapse

Instance Method Details

#format_thousands(value = to_f.to_s) ⇒ Object

Formats number with comma-separated thousands.



375
376
377
378
# File 'lib/kiss/model.rb', line 375

def format_thousands(value = to_f.to_s)
  integer, decimal = value.split(/\./, 2)
  integer.reverse.gsub(/(\d{3})/, '\1,').sub(/\,(-?)$/, '\1').reverse + '.' + decimal
end