Ceil Value of a Number

To find ceil value of a number in Go language, use Ceil() function of math package. Ceil(x) returns the least integer value greater than or equal to x.

In this tutorial, we will learn the syntax of Ceil() function, and how to use this function to find the ceil value of a given number.

Syntax

The syntax of Ceil() function is

</>
Copy
math.Ceil(x)

where x is a floating point value of type float64.

Please note that we have to import “math” package to use Ceil() function.

Return Value

The function returns a floating point value of type float64.

Examples

Ceil Value of Positive Number

In the following program, we take a float value in x, and find its ceil value.

example.go

</>
Copy
package main

import (
	"fmt"
	"math"
)

func main() {
	x := 3.14
	result := math.Ceil(x)
	fmt.Println("Ceil Value :", result)
}

Output

Ceil Value : 4

Ceil Value of Negative Number

In the following program, we take a negative floating value and find its ceil value.

example.go

</>
Copy
package main

import (
	"fmt"
	"math"
)

func main() {
	x := -3.14
	result := math.Ceil(x)
	fmt.Println("Ceil Value :", result)
}

Output

Ceil Value : -3

Conclusion

In this Golang Tutorial, we learned how to find ceil value of a given Float value in Go language, with example programs.