/ Published in: Ruby
Format an integer with commas to make it more readable
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def number_with_delimiter(number, delimiter=",") number.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}") end a=1024 p number_with_delimiter(a)