[Golang系列] go中(int,int64,uint,string,float,bool,interface)类型相互转换
int→string
string := strconv.Itoa(int)
int→int64
int64_ := int64(int)
int64→string
string := strconv.FormatInt(int64,10)
int→float
float := float32(int)
float := float64(int)
int→uint64
uint64 := uint64(int)
float→string
string := strconv.FormatFloat(float64,'E',-1,64)
string := strconv.FormatFloat(float32,'E',-1,32)
参数解释:表示格式:‘f’(ddd.dddd)、‘b’(-ddddp±ddd,指数是二进制)、’e’(-d.dddde±dd,指数是十进制)、’E’(-d.ddddE±dd,指数是十进制)、’g’(指数大时,用’e’格式,否则’f’格式)、’G’(指数大时,用’E’格式,否则’f’格式)
float→int64
int64 := int64(float)
float→int
int := int(float)
string→int
int, err := strconv.Atoi(string)
string→int64
int64, err := strconv.ParseInt(string, 10, 64)
string→float
float,err := strconv.ParseFloat(string,64)
float,err := strconv.ParseFloat(string,32)
string→bool
bool, err := strconv.ParseBool("true")
bool→string
string := strconv.FormatBool(true)
interface→int
interface.(int64)
interface→string
interface.(string)
interface→float
interface.(float64)
interface.(float32)
interface→bool
interface.(bool)
uint64→string
string := strconv.FormatUint(uint64, 10)