1.string转int
#string到int
int,err:=strconv.Atoi(string)
#string到int64
int64, err := strconv.ParseInt(string, 10, 64)
2.int转string
#int到string
string:=strconv.Itoa(int)
#int64到string
string:=strconv.FormatInt(int64,10)
3.string转float
#string到float64
float,err := strconv.ParseFloat(string,64)
#string到float32
float,err := strconv.ParseFloat(string,32)
4.float转string
#float到string
string := strconv.FormatFloat(float32,'E',-1,32)
string := strconv.FormatFloat(float64,'E',-1,64)
5.float转int
var x float64 = 6.9
y := int64(x)
6.int转float
var i int64 = 9
i2f = float64(i)
网友评论