中文数字转阿拉伯数字

拿去用!!!

cn_dict = {
        u'一': '1', u'二': '2', u'三': '3', u'四': '4', u'五': '5', u'六': '6',
        u'七': '7', u'八': '8', u'九': '9', u'十': '10', u'百': '100', u'千': '1000',
    }


    def __cn2num(self, order_list):
        """将汉字转为数据"""
        order_list = [o.strip() for o in order_list]
        o_list = []
        for order in order_list:
            if order.isdigit():
                o_list.append(order)
            else:
                for i in order:
                    if i not in self.cn_dict:
                        return None
                l = len(order)  #order contain chinese number
                if l == 1:
                    o_list.append(self.cn_dict[order])
                elif l == 2:
                    if u'十' in order:
                        if order.index(u'十'):
                            o_list.append(self.cn_dict[order[0]] + '0')
                        else:
                            o_list.append('1' + self.cn_dict[order[1]])
                    elif u'百' in order:
                        o_list.append(self.cn_dict[order[0]] + '00')
                    else:
                        print "***"*20
                        print order
                elif l == 3:
                    if order.index(u'十') == 1:
                        o_list.append(self.cn_dict[order[0]] + self.cn_dict[order[2]])
                else:
                    return None
        return ','.join(o_list)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容