I\'m trying to make a number like 1234567 go to be 1,234,567, but need some help. My thoughts were that I could use a split with \\d{3} and then join a , to that. T
\\d{3}
More precise code (handles integers only, as OP did not mention floats!):
def group_digits(n) n.to_s.chars .reverse .each_slice(3) .map(&:join) .join(",") .reverse end