util.go 350 B

1234567891011121314151617181920
  1. package model
  2. import (
  3. "math"
  4. "strconv"
  5. )
  6. // CalNum2SufStr int64转换带后缀字符串(K,W,E)
  7. func CalNum2SufStr(n int64) string {
  8. var f float64
  9. var s string
  10. if n > 1000 {
  11. f = float64(n) / 1000
  12. s = strconv.FormatFloat(math.Ceil(f), 'f', 0, 64) + "k"
  13. } else {
  14. f = float64(n)
  15. s = strconv.FormatFloat(f, 'f', 0, 64)
  16. }
  17. return s
  18. }