go 数据类型转换

使用strconv 包

首先需要import strconv包

//string to int
i,err := strconv.Atoi(str)
// string to int64
i64,err := strconv.ParseInt(str,10,64)//将str转为10进制64位int型
//int to string
str,err := strconv.Itoa(i)
//int64 to string
str := strconv.FormatInt(i64,10)//10 表示10进制

获取变量的数据类型

首先也是需要import reflect

t := reflect.TypeOf(i)
log.Println(t)