Method: Currentize.format

Defined in:
lib/Currentize.rb

.format(number, currency = "$") ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/Currentize.rb', line 4

def self.format(number, currency = "$")
  arr = number.to_s.split("").reverse
  currentized = ""
  arr.each_with_index do |n, idx|
    if idx % 3 == 0 && idx > 0
      currentized << ","
      currentized << n
    else
      currentized << n
    end
  end
  currency + currentized.reverse
end