#string到int
int,err:=strconv.Atoi(string)
#string到int64
int64, err := strconv.ParseInt(string, 10, 64)
#int到string
string:=strconv.Itoa(int)
#int64到string
string:=strconv.FormatInt(int64,10)
Tips: int样式的string可以转float, float样式的string转int会返回error.
intStr := "88"
int2float, err := strconv.ParseFloat(intStr, 64)
if err != nil{
fmt.Println(err) // nil 无error
}
fmt.Println(int2float) // 88
floatStr := "8.0"
float2int, err := strconv.ParseInt(floatStr,10,64)
if err != nil{
fmt.Println(err) //strconv.ParseInt: parsing "8.0": invalid syntax
}
fmt.Println(float2int) //0