go Itoa()方法,int转string

Itoa()方法语法

func Itoa(i int) string

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

Itoa is equivalent to FormatInt(int64(i), 10)

即,golang的strconv标准库模块中的Itoa()方法,可以将int类型的值转换为string字符串,是FormatInt(i,10)的简写。


strconv.Itoa()方法实例代码

实例中的reflect.TypeOf()方法可以返回go中数据的类型:

func main() {
	var num_str string = strconv.Itoa(123)
	fmt.Println(reflect.TypeOf(num_str))
}

运行go文件,得到输出:

string

全栈后端 / go语法 :













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