mirror of
https://github.com/jefferyjob/go-easy-utils.git
synced 2025-10-21 22:19:23 +08:00
42 lines
892 B
Go
42 lines
892 B
Go
package anyUtil
|
|
|
|
import (
|
|
"strconv"
|
|
)
|
|
|
|
// AnyToStr 任意类型数据转string
|
|
func AnyToStr(input interface{}) string {
|
|
switch v := input.(type) {
|
|
case string:
|
|
return v
|
|
case int:
|
|
return strconv.Itoa(v)
|
|
case int8:
|
|
return strconv.FormatInt(int64(v), 10)
|
|
case int16:
|
|
return strconv.FormatInt(int64(v), 10)
|
|
case int32:
|
|
return strconv.FormatInt(int64(v), 10)
|
|
case int64:
|
|
return strconv.FormatInt(v, 10)
|
|
case uint:
|
|
return strconv.FormatUint(uint64(v), 10)
|
|
case uint8:
|
|
return strconv.FormatUint(uint64(v), 10)
|
|
case uint16:
|
|
return strconv.FormatUint(uint64(v), 10)
|
|
case uint32:
|
|
return strconv.FormatUint(uint64(v), 10)
|
|
case uint64:
|
|
return strconv.FormatUint(v, 10)
|
|
case float32:
|
|
return strconv.FormatFloat(float64(v), 'f', -1, 32)
|
|
case float64:
|
|
return strconv.FormatFloat(v, 'f', -1, 64)
|
|
case bool:
|
|
return strconv.FormatBool(v)
|
|
default:
|
|
return ""
|
|
}
|
|
}
|