Skip to content

Instantly share code, notes, and snippets.

@hokamoto
Last active December 24, 2019 09:06
Show Gist options
  • Save hokamoto/8433533 to your computer and use it in GitHub Desktop.
Save hokamoto/8433533 to your computer and use it in GitHub Desktop.
convert to Japanese Numerals
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