個人的に必要に迫られたので作ってみた。今更python2ですスイマセン。

最新版(?)は https://gist.github.com/kamawanu/bd962a528a3d0337aad5ca35719fbc43#file-jpnumeric-py にあります。

jpnumeric.py
#!/usr/bin/env python2
# !-*- coding:utf-8 -*-

import re

qnums = [
    u"00零", u"11一壱", u"22二弐", u"33三参", u"44四", u"55五伍", u"66六", u"77七", u"88八", u"99九",
    u"万萬", u"十拾", u"千阡",
]

qnums = [list(x) for x in qnums]

del x

qmandigit = [
    [u"兆", 12],
    [u"億", 8],
    [u"万", 4],
    [u"千", 3],
    [u"百", 2],
    [u"十", 1],
    [u"z", 0],  # 番人
]

qmanany = re.compile(r"(\d+)(\D)")
qmandict = dict(qmandigit)


def to_int(src):
    # src = src
    for qmap in qnums:  # 和数字を先にある程度数字に変換
        for q1 in qmap[1:]:
            src = src.replace(q1, qmap[0])
    total = 0  # 合計
    ototal = 0  # 万進法未満の値
    for qk in qmanany.finditer(src + qmandigit[-1][0]):  # 単位文字で分割
        pick = qk.group(1)  # 今回の数字
        jkn = qmandict[qk.group(2)]  # の桁
        if jkn < 4:
            ototal += int(pick) * (10 ** jkn)
        else:
            ototal += int(pick)
            total += ototal * (10 ** jkn)
            ototal = 0
        pass
    total += ototal  # 万未満の残り
    return total

Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.