ceil Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/ceil/ Wed, 25 Mar 2020 17:44:03 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.1 https://i0.wp.com/golangbyexamples.com/wp-content/uploads/2021/05/cropped-go_border-1.png?fit=32%2C32&ssl=1 ceil Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/ceil/ 32 32 159787465 Ceil of a number in Go (Golang) https://vikasboss.github.io/ceil-number-golang/ https://vikasboss.github.io/ceil-number-golang/#respond Wed, 25 Mar 2020 16:56:26 +0000 https://vikasboss.github.io/?p=1805 Overview math package of GO provides a Ceil method that can be used to get the ceil of a number. Ceil of a number is the least integer value greater than or...

The post Ceil of a number in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
Overview

math package of GO provides a Ceil method that can be used to get the ceil of a number. Ceil of a number is the least integer value greater than or equal to that number.

Below is the signature of the function. It takes input a float and also returns a float.

func Ceil(x float64) float64

Some special cases of ceil function are

  • Ceil(±0) = ±0
  • Ceil(±Inf) = ±Inf
  • Ceil(NaN) = NaN

Code:

package main

import (
    "fmt"
    "math"
)

func main() {
    res := math.Ceil(1.6)
    fmt.Println(res)

    res = math.Ceil(-1.6)
	fmt.Println(res)
    
    res = math.Ceil(1)
    fmt.Println(res)
}

Output:

2
-1
1

The post Ceil of a number in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
https://vikasboss.github.io/ceil-number-golang/feed/ 0 1805