LoginSignup
0
0

More than 1 year has passed since last update.

Yen to Int in python3

Last updated at Posted at 2021-08-21
  • 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
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0