Go Ceil()
Published Jul 10, 2023
Contribute to Docs
The Ceil() function returns a given decimal number rounded up to the next highest integer.
Syntax
import "math"
roundedNumber := math.Ceil(floatingNumber)
The Ceil() function receives a value of type float64 and returns a single value of the same type. This returned value is the next highest integer equal to or greater than the argument.
- When passing
Ceil(±Inf), the returned value will be the same as the argument. - When passing
Ceil(Nan), the returned value will be alsoNan. - When passing
Ceil(±0), the returned value will be exactly the same as the argument.
Example
package mainimport ("math" // Required"fmt")func main(){score := 18.54result := math.Ceil(score)fmt.Print(score, " rounded up is ", result, ".")}
The expected output is as follows:
18.54 rounded up is 19.
Codebyte Example
The example below is runnable and shows how Ceil() handles negative numbers.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Go on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn how to use Go (Golang), an open-source programming language supported by Google!
- Beginner Friendly.6 hours