This can actually be done relatively easy in a function:
def convert_kanji(self, zahl):
japnumber = ("兆", "億", "万")
jap_factors = {
"兆": 1000000000000,
"億": 100000000,
"万": 10000
}
#Define the variables
converted_number = 0
already_found = False
found_kanji_previous = 0
try: #If the number can be returned as an integer (i.e. no Kanji in it) -> do it
return(int(zahl))
except ValueError: #If not, disintegrate it
for key in japnumber: #do it for every Kanji
if key in zahl: #If it has been found in the original string:
gef_kanji = zahl.find(key) #mark, which Kanji has been found
if not already_found: #if it is the first kanji:
intermediate_step = int(zahl[:gef_kanji]) * jap_factors[key] #Convert the number in front of the Kanji with the appropriate factor
converted_number = intermediate_step
already_found = True
found_kanji_previous = gef_kanji
else: #for sll other kanjis
intermediate_step = int(zahl[found_kanji_previous+1:gef_kanji]) * jap_factors[key]
converted_number = converted_number + intermediate_step #sum them up
found_kanji_previous = gef_kanji
if len(zahl) > (found_kanji_previous+1):
converted_number = converted_number + int(zahl[found_kanji_previous+1:])
return converted_number
This is still relatively simple. It can only accept numbers in the form of 2314兆3424億3422万2342.
Also the code might be extremely bad, because this was actually my first program in a long long time. But it might be a good starting point for you.
I am actually currently working on a easy converter which will convert japanese numbers into easy to read western ones (e.g. converting 231億 to “23 billion 100 million”; it actually already does that). I guess there is much do be done, e.g. full-width characters, numbers completely in Kanji etc. If I have tackled all that, I might upload it similarily as kanjinums :D