官方的math 包中提供了取整的方法,向上取整math.Ceil() ,向下取整math.Floor()
package main import ( "fmt" "math" ) func main(){ x := 1.1 fmt.Println(math.Ceil(x)) // 2 fmt.Println(math.Floor(x)) // 1 }
官方的math 包中提供了取整的方法,向上取整math.Ceil() ,向下取整math.Floor()
package main import ( "fmt" "math" ) func main(){ x := 1.1 fmt.Println(math.Ceil(x)) // 2 fmt.Println(math.Floor(x)) // 1 }