Go 语言提供了运行时反射的内置支持实现,并允许程序在反射包的帮助下操作任意类型的对象。 Golang 中的reflect.Float()函数用于获取v 的底层值,作为float64。要访问此函数,需要在程序中导入反射包。
Syntax:
Parameters: This function does not accept any parameter.
Return Value: This function returns the v’s underlying value, as a float64.
下面的例子说明了上述方法在 Golang 中的使用:
示例 1:
func (v Value) Float() float64
输出:
// Golang program to illustrate
// reflect.Float() Function
package main
import (
"fmt"
"reflect"
)
func main() {
fmt.Println(reflect.ValueOf(1.2).Float())
}
示例 2:
1.2
输出:
// Golang program to illustrate
// reflect.Float() Function
package main
import (
"fmt"
"reflect"
)
const a = 1.2
const b = 3
func main() {
fmt.Println("Number a : ", a)
fmt.Println("Number b : ", b)
c := a + b
// use of Float() method
fmt.Println(reflect.ValueOf(c).Float())
}