数字 互换 字符串

总结了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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值