go 类型转换

it2022-05-05  168

//跨大类型转换,可以使用strconv包提供的函数     // 字符串转int:Atoi()     // int转字符串: Itoa()     // ParseTP类函数将string转换为TP类型:ParseBool()、ParseFloat()、ParseInt()、ParseUint()。因为string转其它类型可能会失败,所以这些函数都有第二个返回值表示是否转换成功     // 其它类型转string类型:FormatBool()、FormatFloat()、FormatInt()、FormatUint()     // AppendTP类函数用于将TP转换成字符串后append到一个slice中:AppendBool()、AppendFloat()、AppendInt()、AppendUint() ----------------------------- package main import (     "fmt"     "strconv" ) func main() {     var f1 float32 = 1.1     ff1 := float64(f1)     var f2 = 2.63 //默认是floate64     ff2 := float32(f2)     fmt.Println(f1, ff1, f2, ff2)     var s = "hello"     var i = 10     fmt.Println(s, i)     ii := string(i)     fmt.Println(ii)     fmt.Printf("ii is of type %T\n", ii)       //调用包下的方法 需要 包.方法名 strconv.Atoi("a")     d, e := strconv.Atoi("a") //只能转化可以转化为数字的字符     if e != nil {         fmt.Println(e)     } else {         fmt.Println(d)     } }

转载于:https://www.cnblogs.com/songhuan999999/p/11186451.html

相关资源:各显卡算力对照表!

最新回复(0)