Go 语言类型转换

package main

import "fmt"

func main() {
var sum int = 17
var count int = 5
var mean float32

mean = float32(sum)/float32(count)
fmt.Printf("mean 的值为: %f\n",mean)
}

go 不支持隐式转换类型

错:

package main
import "fmt"

func main() {
var a int64 = 3
var b int32
b = a
fmt.Printf("b 为 : %d", b)
}

对:

package main
import "fmt"

func main() {
var a int64 = 3
var b int32
b = int32(a)
fmt.Printf("b 为 : %d", b)
}

posted @ 2023-08-14 20:12  妇愁者纞萌  阅读(3)  评论(0编辑  收藏  举报