zl程序教程

您现在的位置是:首页 >  其他

当前栏目

[Golang] 向上取整和向下取整的实现

2023-02-18 15:36:51 时间

官方的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
}