Created
June 23, 2010 12:01
-
-
Save kdmsnr/449840 to your computer and use it in GitHub Desktop.
This file contains 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
# -*- 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