-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_to_string.go
44 lines (42 loc) · 922 Bytes
/
convert_to_string.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package u
import (
"fmt"
"strconv"
)
// ToString val to string
func ToString(val interface{}) string {
switch v := val.(type) {
case string:
return v
case []byte:
return string(val.([]byte))
case int:
return strconv.Itoa(val.(int))
case int8:
return strconv.Itoa(int(val.(int8)))
case int16:
return strconv.Itoa(int(val.(int16)))
case int32:
return strconv.Itoa(int(val.(int32)))
case int64:
return strconv.Itoa(int(val.(int64)))
case uint:
return strconv.Itoa(int(val.(uint)))
case uint8:
return strconv.Itoa(int(val.(uint8)))
case uint16:
return strconv.Itoa(int(val.(uint16)))
case uint32:
return strconv.Itoa(int(val.(uint32)))
case uint64:
return strconv.Itoa(int(val.(uint64)))
case float32:
return fmt.Sprintf("%.2f", val.(float32))
case float64:
return fmt.Sprintf("%.2f", val.(float64))
case bool:
return strconv.FormatBool(val.(bool))
default:
return ""
}
}