go Trunc()

Trunc()方法语法

func Trunc(x float64) float64

go源码对Trunc()方法的介绍:

Trunc returns the integer value of x.

Special cases are:

Trunc(±0) = ±0
Trunc(±Inf) = ±Inf
Trunc(NaN) = NaN

即,golang的math.Trunc()方法用于返回float64类型的参数x的整数部分的浮点数值,如果参数为±0,则返回±0,如果参数为±Inf,则返回±Inf,如果为NaN,则返回NaN。


math.Trunc()方法实例代码

func main() {
	var t float64 = math.Trunc(6.99)
	fmt.Println(t)
	fmt.Println(reflect.TypeOf(t))
}

运行go文件,得到输出:

6
float64

全栈后端 / go语法 :













Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.