cost_income_percent.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """
  2. cost_income_percent字段检查
  3. """
  4. class Cost_income_percentChecker(object):
  5. """
  6. cost_income_percent字段检查
  7. """
  8. def __init__(self):
  9. self.errors_tables = {
  10. "0101": {
  11. "name": "成本/收入小数点位数超过2位",
  12. "parent_name": "金额错误",
  13. "parent_code": "01",
  14. "checkFn": self.check0101
  15. },
  16. "0102": {
  17. "name": "成本/收入<0",
  18. "parent_name": "金额错误",
  19. "parent_code": "01",
  20. "checkFn": self.check0102
  21. }
  22. }
  23. @staticmethod
  24. def check0101(cost_income_percent: str) -> bool :
  25. """
  26. :param price:
  27. :return: 返回true 代表异常
  28. """
  29. # 将数字转换为字符串
  30. number_str = str(cost_income_percent.strip('%'))
  31. # 检查是否有小数点
  32. if '.' in number_str:
  33. # 分割整数部分和小数部分
  34. integer_part, decimal_part = number_str.split('.')
  35. # 返回小数部分的长度
  36. length= len(decimal_part)
  37. else:
  38. length = 0
  39. if length > 2 :
  40. return True
  41. @staticmethod
  42. def check0102(cost_income_percent: str) -> bool :
  43. """
  44. :return: 返回true 代表异常
  45. """
  46. # 去除百分号并转为浮点数
  47. value = float(cost_income_percent.strip('%'))
  48. if value < 0:
  49. return True
  50. else:
  51. return False