Skip to content

Instantly share code, notes, and snippets.

@vmi
Created January 20, 2022 08:32
Show Gist options
  • Save vmi/fc82bfd0f56a9f3a7c27b18d681e0883 to your computer and use it in GitHub Desktop.
Save vmi/fc82bfd0f56a9f3a7c27b18d681e0883 to your computer and use it in GitHub Desktop.
number format 3-digits with comma (ruby)
# https://stackoverflow.com/questions/6458990/how-to-format-a-number-1000-as-1-000
n = 1234567890
puts n.to_s.gsub(/(\d)(?=\d{3}+(?!\d))/, "\\1,")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment