var str3 string = "3.1415926794654167" num3,err := strconv.ParseFloat(str3,32)
var str4 strig = "true" num4,err := strconv.ParseBool(str4)
不能转换会返回error和对应的默认值
字符串和整型快速转换
1 2 3 4 5 6
//整型转字符串 var num1 int32 = 11 var str1 string = strconv.Itoa(int(num1))//Itoa只接收int类型 //字符串转整型 var str1 string = "666" num2,err := strconv.Atoi(str1)
数值类型转字符串的其他方式
1 2 3 4 5 6
var num1 int32 = 111 var str1 string = fmt.Sprintf("%d",num1) var num2 float32 = 3.14 var str2 string = fmt.Sprintf("%f",num2) var num3 bool = true var str3 string = fmt.Sprintf("%v",num3)