Created
January 20, 2022 08:32
-
-
Save vmi/fc82bfd0f56a9f3a7c27b18d681e0883 to your computer and use it in GitHub Desktop.
number format 3-digits with comma (ruby)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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