1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- """
- capital投资金额字段检查
- """
- class CapitalChecker(object):
- """
- 投资金额字段检查
- """
- def __init__(self):
- self.errors_tables = {
- "0103": {
- "name": "投资金额小数点位数超过4位",
- "parent_name": "金额错误",
- "parent_code": "01",
- "checkFn": self.check0103
- },
- "0201": {
- "name": "投资金额<0",
- "parent_name": "金额错误",
- "parent_code": "01",
- "checkFn": self.check0201
- }
- }
- @staticmethod
- def check0103(capital: float) -> bool :
- """
- 投资金额小数点位数超过4位,视为异常
- :param price:
- :return: 返回true 代表异常
- """
- # 将数字转换为字符串
- number_str = str(capital)
- # 检查是否有小数点
- if '.' in number_str:
- # 分割整数部分和小数部分
- integer_part, decimal_part = number_str.split('.')
- # 返回小数部分的长度
- length= len(decimal_part)
- else:
- length = 0
- if length > 4 :
- return True
- @staticmethod
- def check0201(capital: float) -> bool :
- """
- 投资金额<0,视为异常
- :return: 返回true 代表异常
- """
- if capital < 0:
- return True
- return False
|