This does the same thing more succinctly
It converts the number to a string, reverses it, places a comma every three digits (if it is followed by a digit), then reverses it back to its original order.
You might want to make it a function such as
so that you can call the process multiple times
However, this method does not work with numbers that contain 3+ decimals. To solve that:
number = number.to_s.split('.')
This method splits the integer into the whole number part and the decimal part. It then adds the comma to the whole number and then tacks on the second decimal part.
: the second line of that function should have been number to get the first element (the whole number one). Sorry if you viewed it before I realized my mistake.