数字 互换 字符串

总结了golang中字符串和各种int类型之间的相互转换方式:

string转成int: 
int, err := strconv.Atoi(string)
string转成int64: 
int64, err := strconv.ParseInt(string, 10, 64)

string 转成 float64

i1, _ := strconv.ParseFloat(u.Height, 64)
int转成string: 
string := strconv.Itoa(int)
int64转成string: 
string := strconv.FormatInt(int64,10)
以备查询

int64 转 int
strInt64 := strconv.FormatInt(int64, 10)
id16 ,_ := strconv.Atoi(strInt64)

最后的id16为int       该方法是将int64-----> string-------->int
 

C语言在go语言的对应

char -->  C.char -->  byte
signed char -->  C.schar -->  int8
unsigned char -->  C.uchar -->  uint8
short int -->  C.short -->  int16
short unsigned int -->  C.ushort -->  uint16
int -->  C.int -->  int
unsigned int -->  C.uint -->  uint32
long int -->  C.long -->  int32 or int64
long unsigned int -->  C.ulong -->  uint32 or uint64
long long int -->  C.longlong -->  int64
long long unsigned int -->  C.ulonglong -->  uint64
float -->  C.float -->  float32
double -->  C.double -->  float64
wchar_t -->  C.wchar_t  -->  
void * -> unsafe.Pointer

猜你喜欢

转载自blog.csdn.net/qq_40417296/article/details/84952827