package main
import (
"fmt"
"strconv"
)
func main() {
var a1 = "20"
var a2 = "true"
var a3 = "19.862"
n1, _ := strconv.Atoi(a1) //字符串转为整型,_ 位标识符,返回的结果有2个,忽略掉第二个,第二个是用于接收error的错误信息
n6, _ := strconv.ParseInt(a1, 10, 64) //另一种字符串转给整型
n2, _ := strconv.ParseBool(a2) //字符串转布尔型
n3, _ := strconv.ParseFloat(a3, 64) // 字符串转浮点数
fmt.Printf("n1的类型是%T,对应的值是%#v\n", n1, n1)
fmt.Printf("n6的类型是%T,对应的值是%#v\n", n6, n6)
fmt.Printf("n2的类型是%T,对应的值是%#v\n", n2, n2)
fmt.Printf("n3的类型是%T,对应的值是%#v\n", n3, n3)
}
标签:数据类型,fmt,strconv,%#,字符串,Printf,Go,n1,转给
From: https://www.cnblogs.com/bangbangzoutianya/p/17023268.html