蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

60 lines
1012 B

  1. package utils
  2. import (
  3. "math"
  4. )
  5. func CouponFormat(data string) string {
  6. switch data {
  7. case "0.00", "0", "":
  8. return ""
  9. default:
  10. return Int64ToStr(FloatToInt64(StrToFloat64(data)))
  11. }
  12. }
  13. func CommissionFormat(data string) string {
  14. if StrToFloat64(data) > 0 {
  15. return data
  16. }
  17. return ""
  18. }
  19. func HideString(src string, hLen int) string {
  20. str := []rune(src)
  21. if hLen == 0 {
  22. hLen = 4
  23. }
  24. hideStr := ""
  25. for i := 0; i < hLen; i++ {
  26. hideStr += "*"
  27. }
  28. hideLen := len(str) / 2
  29. showLen := len(str) - hideLen
  30. if hideLen == 0 || showLen == 0 {
  31. return hideStr
  32. }
  33. subLen := showLen / 2
  34. if subLen == 0 {
  35. return string(str[:showLen]) + hideStr
  36. }
  37. s := string(str[:subLen])
  38. s += hideStr
  39. s += string(str[len(str)-subLen:])
  40. return s
  41. }
  42. //SaleCountFormat is 格式化销量
  43. func SaleCountFormat(s string) string {
  44. return s + "已售"
  45. }
  46. // 小数格式化
  47. func FloatFormat(f float64, i int) float64 {
  48. if i > 14 {
  49. return f
  50. }
  51. p := math.Pow10(i)
  52. return float64(int64((f+0.000000000000009)*p)) / p
  53. }