Integer values representation

I want to print out integer values like this:

puts "the value is #{x}" => the value is 1234567890

But I want to output to look like:

puts "the value is #{x}" => the value is 1,234,567,890 (or 1_234_567_890)

How do you do this?

Number#format:

1234567890.format                 # => "1,234,567,890"
1234567890.format(delimiter: '_') # => "1_234_567_890"
3 Likes