优化费用总额的解析
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import logging
|
||||
import re
|
||||
from datetime import datetime
|
||||
|
||||
from util import util
|
||||
|
||||
|
||||
# 处理金额类数据
|
||||
def handle_decimal(string):
|
||||
@@ -8,21 +11,28 @@ def handle_decimal(string):
|
||||
if not string:
|
||||
return ""
|
||||
if "." not in string:
|
||||
front = string
|
||||
back = ""
|
||||
if len(string) > 2:
|
||||
result = string[:-2] + "." + string[-2:]
|
||||
else:
|
||||
result = string
|
||||
else:
|
||||
front, back = string.rsplit('.', 1)
|
||||
front = front.replace(".", "")
|
||||
if back:
|
||||
back = "." + back[:2]
|
||||
result = front + back
|
||||
return result[:16]
|
||||
|
||||
front = front[-16:]
|
||||
if back:
|
||||
back = "." + back
|
||||
result = float(front + back)
|
||||
# 金额较大的暂且交给人工确认
|
||||
if result > 100000:
|
||||
return ""
|
||||
else:
|
||||
return front + back
|
||||
|
||||
def parse_money(capital_num, num):
|
||||
if capital_num:
|
||||
try:
|
||||
money = util.chinese_money_to_number(capital_num)
|
||||
return capital_num, money
|
||||
except Exception as e:
|
||||
logging.warning("大写金额解析失败", exc_info=e)
|
||||
|
||||
return num, handle_decimal(num)
|
||||
|
||||
|
||||
# 处理日期类数据
|
||||
@@ -161,7 +171,3 @@ def handle_age(string):
|
||||
string = string.split("岁")[0]
|
||||
num = re.sub(r'\D', '', string)
|
||||
return num[-3:]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(handle_decimal(" "))
|
||||
Reference in New Issue
Block a user