Last active
December 24, 2019 09:06
-
-
Save hokamoto/8433533 to your computer and use it in GitHub Desktop.
convert to Japanese Numerals
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
class BigDecimal | |
SUFFIX = [['京', 16], ['兆', 12], ['億', 8], ['万', 4]] | |
def convertNumber2JapaneseNumerals | |
number ||= self | |
number_string ||= '' | |
SUFFIX.each do |suffix| | |
if number.exponent >= suffix[1] | |
number_string += number.div(10 ** suffix[1]).to_s + suffix[0] | |
number = number.remainder(10 ** suffix[1]) | |
end | |
end | |
return number_string + number.split[1].to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment