go语言把int转为字符串的方法:【fmt.Println(strconv.Itoa(100))】。如果要把字符串转为整形,可以使用【i, _ := strconv.Atoi("100") fmt.Println(i)】。
本文操作环境:windows10系统、Go 1.11.2、thinkpad t480电脑。
整形转字符串
fmt.Println(strconv.Itoa(100))
该方法的源码是:
// Itoa is shorthand for FormatInt(i, 10). func Itoa(i int) string { return FormatInt(int64(i), 10) }
可以看出是FormatInt方法的简单实现。
字符串转整形
i, _ := strconv.Atoi("100") fmt.Println(i)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。