strconv.FormatInt用法与使用

1.干什么用的

strconv.FormatInt(i int64, base int)
解释:将i转化为base的展现形式

2.事例

fmt.Println(strconv.FormatInt(8, 10))   // out 8
fmt.Println(strconv.FormatInt(9, 2))     //out 1001
fmt.Println(strconv.FormatInt(100, 10)) //out 100
fmt.Println(strconv.FormatInt(011, 10)) //9

解释: 其实很好理解,比如strconv.FormatInt(9, 2),其实就是把9换成2进制形式展示,其他同
但是对于strconv.FormatInt(011, 10)存在一些异议的,直接看代码

func FormatInt(i int64, base int) string {
    if fastSmalls && 0 <= i && i < nSmalls && base == 10 {
        return small(int(i))
    }
    _, s := formatBits(nil, uint64(i), base, i < 0, false)
    return s
}

首先 011大于0,其次base(2) 不等于10,所以会做一个转换uint64(i)

fmt.Println(uint64(011))   //out: 9

So,结果就是这个样子

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容