我正在看“A Tour of Go”,看到package mainimport ( "fmt" "math")func main() { var x, y int = 3, 4 var f float64 = math.Sqrt(float64(x*x + y*y)) var z uint = uint(f) fmt.Println(x, y, z, f)}當(dāng)我運(yùn)行此代碼時(shí),它打印3 4 5 5不應(yīng)該是3 4 5.0我是全新的去查找文檔,但我找不到任何答案
1 回答
largeQ
TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個(gè)贊
math.Sqrt -> float64
但是您正在使用 .嘗試fmt.Println
fmt.Printf("%.1f", f)"Println formats using the default formats for its operands and writes to standard output." https://golang.org/pkg/fmt/#Println
- 1 回答
- 0 關(guān)注
- 115 瀏覽
添加回答
舉報(bào)
0/150
提交
取消
