Yen to Int in python3


  • source
def _yenToInt(src):
    print("src:",src)
    ret = 0
    ss = src.split("千")
    if len(ss) > 1:
        ret = ret + int(ss[0])*1000
        src = ss[1]
    ss = src.split("百")
    if len(ss) > 1:
        ret = ret + int(ss[0])*100
        src = ss[1]
    ss = src.split("十")
    if len(ss) > 1:
        ret = ret + int(ss[0])*10
        src = ss[1]
    if src != "":
        ret = ret + int(src)
    return ret

def yenToInt(money):
    print("money:",money)
    money = money.replace(',','')
    money = money.replace('円','')
    ms = money.split("兆")
    if len(ms) > 1:
        sub = int(_yenToInt(ms[0]))*1000000000000
        if ms[1].strip() == "":
            return sub
        else:
            return sub+yenToInt(ms[1])
    ms = money.split("億")
    if len(ms) > 1:
        sub = int(_yenToInt(ms[0]))*100000000
        if ms[1].strip() == "":
            return sub
        else:
            return sub+yenToInt(ms[1])
    ms = money.split("万")
    if len(ms) > 1:
        sub = int(_yenToInt(ms[0]))*10000
        if ms[1].strip() == "":
            return sub
        else:
            return sub+yenToInt(ms[1])
    #print(money,int(money))
    return int(_yenToInt(money))
  • execution example
# python3 test.py '2,300万円'
23000000
# python3 test.py '37億5500万円'
3755000000
# python3 test.py '11億7719万円'
1177190000