Golang 数据类型转换

string To int

  • 字符串为纯数字,值为:123456

    aInt, _ := strconv.Atoi("123456")
    fmt.Printf("数据类型: %T, 值: %d", aInt, aInt)

    image.png

  • 字符串不为纯数字,值为:0

    aInt, _ := strconv.Atoi("123456d")
    fmt.Printf("数据类型: %T, 值: %d", aInt, aInt)

    image.png

int To string

  • 纯数字, 值为: 1234

    aInt := strconv.Itoa(1234)
    fmt.Printf("数据类型: %T, 值: %v", aInt, aInt)

    image.png

评论

暂无评论