Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kdmsnr/449840 to your computer and use it in GitHub Desktop.
Save kdmsnr/449840 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
numbers = [100, 100000500, 123456789]
numbers.each do |number|
scales = ["", "万", "億", "兆"]
puts number.to_s.gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, "\\1,").split(',').reverse.inject("") {|result, item|
scale = scales.shift
item = item.to_i.to_s.gsub(/(\d)(?=(?:\d\d\d)+(?!\d))/, '\1,')
result = item + scale + result unless item == "0"
result
} + '円'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment