go FormatInt()方法,转换int为string

FormatInt()方法语法

func FormatInt(i int64, base int) string

go源码对FormatInt()方法的介绍:

FormatInt returns the string representation of i in the given base, for 2 <= base <= 36. The result uses the lower-case letters 'a' to 'z' for digit values >= 10.

即,golang的strconv.FormatInt(),可以将base指定进制的数值i转换为字符串string,其中base介于[2,36]之间,在不同的进制中,base大于10的非十进制转换的值同行会以小写的a到z来表示大于10的值,比如十六进制中常以f来表示15。


strconv.FormatInt()方法实例代码

func main() {
	var str string = strconv.FormatInt(255, 16)
	fmt.Println(str)
}

运行go文件,得到输出:

ff

全栈后端 / go语法 :













Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.