Sha256: 683538083a0ac5e7d00cbbe5028ea34b2e2f93b6a8cb16ae27a2262937d47770
Contents?: true
Size: 503 Bytes
Versions: 2
Compression:
Stored size: 503 Bytes
Contents
class Numeric ## # Format a number as human readable currency. # # === Examples # # 10.format_currency => '10' # 10.99.format_currency => '10.99' # 10.9999.format_currency => '10.99' # 1000.99.format_currency => '1,000.99' # 1000000.99.format_currency => '1,000,000.99' # def format_currency parts = self.to_s.split '.' parts[0].gsub! /(\d)(?=(\d\d\d)+(?!\d))/, '\1,' parts.join('.').gsub /(\.\d{2})(\d+)/, '\1' rescue self.to_s end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rext-0.7.0 | lib/rext/numeric/helpers.rb |
rext-0.6.2 | lib/rext/numeric/helpers.rb |