golang 类型转换只能显性转换 不能自动转换 基本数据类型间的转换 var x1 int = 2 var x2 int16 var x3 int8 x2 = 200 + x1 x3 = 200 + x1 .\test.go:3:8: imported and not used: "fmt" .\test.go:21:5: cannot use 200 + x1 (type int) as type int16 in assignment .\test.go:22:5: cannot…
简单整理一下Golang的基本类型转换,作为备忘: 1.整形到字符串: var i int = 1 var s string 3. s = strconv.Itoa(i) 或者 s = FormatInt(int64(i), 10) 2.字符串到整形 var s string = "1" var i int i, err = strconv.Atoi(s) 或者 i, err = ParseInt(s, 10, 0) 3.字符串到float(32 / 64) var s st…