优惠券额度包
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.

67 lines
1.1 KiB

  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. if StrToInt(s) > 0 {
  45. if StrToInt(s) >= 10000 {
  46. num := FloatFormat(StrToFloat64(s)/10000, 2)
  47. s = Float64ToStr(num) + "w"
  48. }
  49. return s + "已售"
  50. }
  51. return ""
  52. }
  53. // 小数格式化
  54. func FloatFormat(f float64, i int) float64 {
  55. if i > 14 {
  56. return f
  57. }
  58. p := math.Pow10(i)
  59. return float64(int64((f+0.000000000000009)*p)) / p
  60. }