123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- """
- cost_income_percent字段检查
- """
- class Cost_income_percentChecker(object):
- """
- cost_income_percent字段检查
- """
- def __init__(self):
- self.errors_tables = {
- "0101": {
- "name": "成本/收入小数点位数超过2位",
- "parent_name": "金额错误",
- "parent_code": "01",
- "checkFn": self.check0101
- },
- "0102": {
- "name": "成本/收入<0",
- "parent_name": "金额错误",
- "parent_code": "01",
- "checkFn": self.check0102
- }
- }
- @staticmethod
- def check0101(cost_income_percent: str) -> bool :
- """
- :param price:
- :return: 返回true 代表异常
- """
- # 将数字转换为字符串
- number_str = str(cost_income_percent.strip('%'))
- # 检查是否有小数点
- if '.' in number_str:
- # 分割整数部分和小数部分
- integer_part, decimal_part = number_str.split('.')
- # 返回小数部分的长度
- length= len(decimal_part)
- else:
- length = 0
- if length > 2 :
- return True
- @staticmethod
- def check0102(cost_income_percent: str) -> bool :
- """
- :return: 返回true 代表异常
- """
- # 去除百分号并转为浮点数
- value = float(cost_income_percent.strip('%'))
- if value < 0:
- return True
- else:
- return False
|