我正在尝试这个简单的代码:
var f1 float64 = 23.435
fmt.Println(f1.Acos())
但这给了我以下错误:
f1.Acos undefined (type float64 has no field or method Acos)
有人可以帮助我了解使用内置方法的正确方法吗?
最佳答案
Acos
是math
包的功能,而不是float64的内置方法,因此必须首先将其导入
import (
"fmt"
"math"
)
然后,as per documentation,您将
f1
作为参数传递给math.Acos
fmt.Println(math.Acos(f1))
关于go - 如何在Golang中使用内置方法?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36592199/