Skip to content

Instantly share code, notes, and snippets.

@JFickel
Created April 23, 2013 04:47
Show Gist options
  • Save JFickel/5440923 to your computer and use it in GitHub Desktop.
Save JFickel/5440923 to your computer and use it in GitHub Desktop.
def separate_comma(number)
@interjects = (number.to_s.length - 1) / 3
@number = number.to_s.split('')
@comma_number = []
@number = @number.reverse
@number.each_slice(3) do |slice|
@comma_number << slice
if @interjects > 0
@comma_number << ","
@interjects -= 1
end
end
@comma_number.flatten.reverse.join
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment