Go语言string,int,int64 ,float之间类型转换方法
(1)int转string
1 2 |
|
(2)int64转string
1 2 |
|
第二个参数为基数,可选2~36
注:对于无符号整形,可以使用FormatUint(i uint64, base int)
(3)string转int
1 |
|
(4)string转int64
1 |
|
第二个参数为基数(2~36),第三个参数位大小表示期望转换的结果类型,其值可以为0, 8, 16, 32和64,分别对应 int, int8, int16, int32和int64
(5)float相关
float转string:
1 2 |
|
函数原型及参数含义具体可查看:https://golang.org/pkg/strconv/#FormatFloat
string转float:
1 2 3 |
|
PS:go语言string、int、int64互相转换
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
总结
以上所述是小编给大家介绍的Go语言string,int,int64 ,float之间类型转换方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
您可能感兴趣的文章:
- mongodb错误tcmalloc: large alloc out of memory, printing stack and exiting解决办法
- mongodb exception: $concat only supports strings, not NumberInt32解决办法
- Go语言interface详解
- go语言中的interface使用实例
- golang实现unicode转换为字符串string的方法
原文链接:http://www.cnblogs.com/vdvvdd/archive/2017/07/20/7211122.html
如对本文有疑问,请提交到交流社区,广大热心网友会为你解答!! 点击进入社区
- 上一篇 »PHP数据类型转换, 保留小数问题
- 下一篇 »PHP的数据类型与常量使用