type.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package util
  2. import (
  3. "fmt"
  4. "reflect"
  5. )
  6. // IsNull 判断是否为空字符串
  7. func IsNull(s string) string {
  8. if s == "" {
  9. return "0"
  10. }
  11. return s
  12. }
  13. // IsBlank 判断 reflect.Value 是否为空
  14. func IsBlank(value reflect.Value) bool {
  15. switch value.Kind() {
  16. case reflect.String:
  17. return value.Len() == 0
  18. case reflect.Bool:
  19. return !value.Bool()
  20. case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
  21. return value.Int() == 0
  22. case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
  23. return value.Uint() == 0
  24. case reflect.Float32, reflect.Float64:
  25. return value.Float() == 0
  26. case reflect.Interface, reflect.Ptr:
  27. return value.IsNil()
  28. }
  29. return reflect.DeepEqual(value.Interface(), reflect.Zero(value.Type()).Interface())
  30. }
  31. func GetNumString(num int64) string {
  32. if num < 10000 {
  33. return fmt.Sprintf("%v", num)
  34. } else if num >= 10000 && num < 100000000 {
  35. mean := float32(num) / float32(10000)
  36. str := fmt.Sprintf("%.1f", mean)
  37. return str + "万"
  38. } else {
  39. mean := float32(num) / float32(100000000)
  40. str := fmt.Sprintf("%.1f", mean)
  41. return str + "亿"
  42. }
  43. }