base.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #coding=utf-8
  2. class Formater():
  3. @staticmethod
  4. def formatStr(value):
  5. res = u''
  6. if value != None:
  7. try:
  8. res = str(value)
  9. except:
  10. pass
  11. return res
  12. @staticmethod
  13. def formatCount(value):
  14. return int(round(float(value or 0) * 100,0))
  15. @staticmethod
  16. def formatPrice(value):
  17. return int(round(float(value or 0) * 100,0))
  18. @staticmethod
  19. def formatCountShow(value):
  20. return '%.2f' % (float(value or 0)/100.0)
  21. @staticmethod
  22. def formatPriceShow(value):
  23. return '%.2f' % (float(value or 0)/100.0)
  24. @staticmethod
  25. def formatAmount(value):
  26. return int(round(float(value or 0) * 10000,0))
  27. @staticmethod
  28. def formatAmountShow(value):
  29. return '%.2f' % (float(value or 0) / 10000.0 + 0.0000001)
  30. class CustomFormaterByUser():
  31. @staticmethod
  32. def formatEmptyStr(value,user):
  33. return Formater.formatEmptyStr(value)
  34. @staticmethod
  35. def formatEmptyFloat(value, user):
  36. #return round(value or 0, 2)
  37. return Formater.formatEmptyFloat(value)
  38. @staticmethod
  39. def formatTime(value,user):
  40. return Formater.formatTime(value)
  41. @staticmethod
  42. def formatDate(value, user):
  43. return Formater.formatDate(value)
  44. @staticmethod
  45. def formatCountShow(value,user):
  46. return Formater.formatCountShow(value)
  47. @staticmethod
  48. def formatPartAmountShow(value, user):
  49. return Formater.formatAmountShow(value)