wangshan 3 anni fa
parent
commit
0d84ee0d99
1 ha cambiato i file con 18 aggiunte e 0 eliminazioni
  1. 18 0
      common/common.go

+ 18 - 0
common/common.go

@@ -720,3 +720,21 @@ func MathCeil(x float64) int {
 func MathFloor(x float64) int {
 	return int(math.Floor(x + 0/5))
 }
+
+//string
+func InterfaceToStr(x interface{}) string {
+	switch st := reflect.ValueOf(x); st.Kind() {
+	case reflect.Uint, reflect.Uintptr, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
+		return strconv.FormatUint(uint64(st.Uint()), 10)
+	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
+		return strconv.FormatInt(int64(st.Int()), 10)
+	case reflect.Float32, reflect.Float64:
+		return strconv.FormatFloat(float64(st.Float()), 'g', -1, 64)
+	case reflect.Bool:
+		return strconv.FormatBool(st.Bool())
+	}
+	var ret string
+	_ = Bind(x, &ret)
+	return ret
+
+}