package main
import (
"fmt"
"strconv" //引入strconv包
)
func main() {
var str string = "true"
var str2 string = "1234"
var str3 string = "12322.3456"
a, _ := strconv.ParseBool(str)
b, _ := strconv.ParseInt(str2, 10, 0) //注意 文中的0默认int64 ,0也可以换成1-64任意以8 16 32 64 来取小来输出。若>64则 返回0值。10是10进制
c, _ := strconv.ParseFloat(str3, 0) //注意 文中的0默认int64 ,0也可以换成任意数字
fmt.Printf("a type %T a=%v\n", a, a)
fmt.Printf("b type %T b=%v\n", b, b)
fmt.Printf("c type %T c=%v\n", c, c)
//%T是返回一个变量的类型 \n 是换行符
输出
a type bool a=true b type int64 b=1234 c type float64 c=12322.3456