3

# Golang中string、int、int64互相转换

 2 years ago
source link: https://studygolang.com/articles/17814?fr=sidebar
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

# Golang中string、int、int64互相转换

w85278161 · 2019-01-20 18:34:43 · 9377 次点击 · 预计阅读时间不到 1 分钟 · 大约8小时之前 开始浏览    
这是一个创建于 2019-01-20 18:34:43 的文章,其中的信息可能已经有所发展或是发生改变。

Golang中string、int、int64互相转换

使用官方的strconv包即可:

#string到int  
int,err:=strconv.Atoi(string)  
#string到int64  
int64, err := strconv.ParseInt(string, 10, 64)  
#int到string  
string:=strconv.Itoa(int)  
#int64到string  
string:=strconv.FormatInt(int64,10)  ```

同类型之间转换,比如int64到int,直接int(int64)即可;



有疑问加站长微信联系(非本文作者)

280

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:701969077


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK