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
Author And Source
この問題について(Yen to Int in python3), 我々は、より多くの情報をここで見つけました https://qiita.com/adad/items/71c3bcc358139a41b475著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .