【Golang】string、int、int64互相转换

go语言string、int、int64互相转换

// string 到 int 
int, err := strconv.Atoi(string) 

// string到int64 
int64, err := strconv.ParseInt(string, 10, 64) 

// string到float64 
int64, err := strconv.ParseInt(string, 10, 64) 

// int到string 
string := strconv.Itoa(int) 

// int64到string 
string := strconv.FormatInt(int64,10) 

rand := int(Mt_rand(0, 32000))
// randInt := strconv.FormatInt(rand, 10)

// strconv.ParseInt(rand, 10, 64)
encryptKey := strconv.Itoa(rand)

// int64 到 int
currentTime := int(time.Now().Unix()) //时间戳

// 时间戳 到 string
strconv.Itoa(int(time.Now().Unix()))

// float64 转 int
var s float64 = 108.2
intS := int(math.Round(s / 60))

// interface {} 转 int
// interface {} is float64
int(result["rank"].(float64))

你可能感兴趣的:(Golang,golang,算法,开发语言)