Skip to content

Instantly share code, notes, and snippets.

@vpivo
Created March 1, 2013 08:44
Show Gist options
  • Save vpivo/5063318 to your computer and use it in GitHub Desktop.
Save vpivo/5063318 to your computer and use it in GitHub Desktop.
Seperate Numbers with Commas
def separate_comma(number)
if number < 1000
puts "silly"
end
snumb = number.to_s
array = snumb.split('')
cstr = ''
counter = 0
array.reverse.each do |i|
cstr += i
counter += 1
if counter == 3
cstr += ','
counter = 0
end
end
cstr = cstr.reverse
if cstr[0] == ','
cstr.slice!(0,1)
end
puts cstr
end
separate_comma(100000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment