Skip to content

Latest commit

 

History

History
25 lines (19 loc) · 429 Bytes

index.md

File metadata and controls

25 lines (19 loc) · 429 Bytes

类型转换

Golang是强类型语言,而且不会像C、C++那样进行进行隐式类型转换,如下的代码会报错

package main

import "fmt"

func main() {
    var a float32 = 5.6
    var b int = 10
    fmt.Println (a * b)
}

报错如下

invalid operation: a * b (mismatched types float32 and int)

必须进行显式的类型转换才可以相乘

fmt.Println(a * float32(b))