劲创营---任务项目
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

108 lignes
2.0 KiB

  1. package utils
  2. import (
  3. "fmt"
  4. "math"
  5. "strings"
  6. )
  7. func CouponFormat(data string) string {
  8. switch data {
  9. case "0.00", "0", "":
  10. return ""
  11. default:
  12. return Int64ToStr(FloatToInt64(StrToFloat64(data)))
  13. }
  14. }
  15. func CommissionFormat(data string) string {
  16. if data != "" && data != "0" {
  17. return data
  18. }
  19. return ""
  20. }
  21. func HideString(src string, hLen int) string {
  22. str := []rune(src)
  23. if hLen == 0 {
  24. hLen = 4
  25. }
  26. hideStr := ""
  27. for i := 0; i < hLen; i++ {
  28. hideStr += "*"
  29. }
  30. hideLen := len(str) / 2
  31. showLen := len(str) - hideLen
  32. if hideLen == 0 || showLen == 0 {
  33. return hideStr
  34. }
  35. subLen := showLen / 2
  36. if subLen == 0 {
  37. return string(str[:showLen]) + hideStr
  38. }
  39. s := string(str[:subLen])
  40. s += hideStr
  41. s += string(str[len(str)-subLen:])
  42. return s
  43. }
  44. // SaleCountFormat is 格式化销量
  45. func SaleCountFormat(s string) string {
  46. return s + "已售"
  47. }
  48. func SaleCountFormat1(s string) string {
  49. s = strings.ReplaceAll(s, "+", "")
  50. if strings.Contains(s, "万") {
  51. s = strings.ReplaceAll(s, "万", "")
  52. s = Float64ToStrByPrec(StrToFloat64(s)*10000, 0)
  53. }
  54. ex := strings.Split(s, ".")
  55. if len(ex) == 2 && StrToInt(ex[1]) == 0 {
  56. s = ex[0]
  57. }
  58. if StrToInt(s) > 0 {
  59. s = Comm(s)
  60. return s
  61. }
  62. return "0"
  63. }
  64. func Comm(s string) string {
  65. ex := strings.Split(s, ".")
  66. if len(ex) == 2 && StrToInt(ex[1]) == 0 {
  67. s = ex[0]
  68. }
  69. if StrToInt(s) >= 10000 {
  70. num := FloatFormat(StrToFloat64(s)/10000, 2)
  71. numStr := Float64ToStr(num)
  72. ex := strings.Split(numStr, ".")
  73. if len(ex) == 2 {
  74. if StrToFloat64(ex[1]) == 0 {
  75. numStr = ex[0]
  76. } else {
  77. val := Float64ToStrByPrec(StrToFloat64(ex[1]), 0)
  78. keyMax := 0
  79. for i := 0; i < len(val); i++ {
  80. ch := string(val[i])
  81. fmt.Println(StrToInt(ch))
  82. if StrToInt(ch) > 0 {
  83. keyMax = i
  84. }
  85. }
  86. valNew := val[0 : keyMax+1]
  87. numStr = ex[0] + "." + strings.ReplaceAll(ex[1], val, valNew)
  88. }
  89. }
  90. s = numStr + "万"
  91. }
  92. return s
  93. }
  94. // 小数格式化
  95. func FloatFormat(f float64, i int) float64 {
  96. if i > 14 {
  97. return f
  98. }
  99. p := math.Pow10(i)
  100. return float64(int64((f+0.000000000000009)*p)) / p
  101. }