Golang math.Ceil - Syntax
mixed ceil(mixed n);
The math.Ceil() function in Go programming is used to return the next highest integer value by rounding up value if necessary.
mixed ceil(mixed n);
mixed n |
Specifies the real number (int, long, float, double) / infinity (*Required) |
---|---|
Return mixed |
Returns a number / infinity respective to an input argument. |
Round the floating point number from 1.0 to 2.0 step by 0.1 using ceiling math method and print the resultant in console.
package main
import (
"fmt"
"math"
)
func main() {
var num1 = math.Ceil(1.0)
var num2 = math.Ceil(1.1)
var num3 = math.Ceil(1.2)
var num4 = math.Ceil(1.3)
var num5 = math.Ceil(1.4)
var num6 = math.Ceil(1.5)
var num7 = math.Ceil(1.6)
var num8 = math.Ceil(1.7)
var num9 = math.Ceil(1.8)
var num10 = math.Ceil(1.9)
var num11 = math.Ceil(2.0)
fmt.Println("The ceiling value of 1.0 is", num1);
fmt.Println("The ceiling value of 1.1 is", num2);
fmt.Println("The ceiling value of 1.2 is", num3);
fmt.Println("The ceiling value of 1.3 is", num4);
fmt.Println("The ceiling value of 1.4 is", num5);
fmt.Println("The ceiling value of 1.5 is", num6);
fmt.Println("The ceiling value of 1.6 is", num7);
fmt.Println("The ceiling value of 1.7 is", num8);
fmt.Println("The ceiling value of 1.8 is", num9);
fmt.Println("The ceiling value of 1.9 is", num10);
fmt.Println("The ceiling value of 2.0 is", num11);
}
Round the positive floating point number (random numbers) using ceiling math method and print the resultant in console.
package main
import (
"fmt"
"math"
)
func main() {
var num1 = math.Ceil(1.5698)
var num2 = math.Ceil(1.3093)
var num3 = math.Ceil(1.0087)
var num4 = math.Ceil(1.1038)
var num5 = math.Ceil(1.9573)
var num6 = math.Ceil(1.7462)
var num7 = math.Ceil(1.6427)
var num8 = math.Ceil(1.4128)
var num9 = math.Ceil(1.8099)
var num10 = math.Ceil(1.2743)
var num11 = math.Ceil(2.0001)
fmt.Println("The ceiling value of 1.5698 is", num1);
fmt.Println("The ceiling value of 1.3093 is", num2);
fmt.Println("The ceiling value of 1.0087 is", num3);
fmt.Println("The ceiling value of 1.1038 is", num4);
fmt.Println("The ceiling value of 1.9573 is", num5);
fmt.Println("The ceiling value of 1.7462 is", num6);
fmt.Println("The ceiling value of 1.6427 is", num7);
fmt.Println("The ceiling value of 1.4128 is", num8);
fmt.Println("The ceiling value of 1.8099 is", num9);
fmt.Println("The ceiling value of 1.2743 is", num10);
fmt.Println("The ceiling value of 2.0001 is", num11);
}
Round the negative floating point number (random numbers) using ceiling math method and print the resultant in console.
package main
import (
"fmt"
"math"
)
func main() {
var num1 = math.Ceil(-1.5698)
var num2 = math.Ceil(-1.3093)
var num3 = math.Ceil(-1.0087)
var num4 = math.Ceil(-1.1038)
var num5 = math.Ceil(-1.9573)
var num6 = math.Ceil(-1.7462)
var num7 = math.Ceil(-1.6427)
var num8 = math.Ceil(-1.4128)
var num9 = math.Ceil(-1.8099)
var num10 = math.Ceil(-1.2743)
var num11 = math.Ceil(-2.0001)
fmt.Println("The ceiling value of -1.5698 is", num1);
fmt.Println("The ceiling value of -1.3093 is", num2);
fmt.Println("The ceiling value of -1.0087 is", num3);
fmt.Println("The ceiling value of -1.1038 is", num4);
fmt.Println("The ceiling value of -1.9573 is", num5);
fmt.Println("The ceiling value of -1.7462 is", num6);
fmt.Println("The ceiling value of -1.6427 is", num7);
fmt.Println("The ceiling value of -1.4128 is", num8);
fmt.Println("The ceiling value of -1.8099 is", num9);
fmt.Println("The ceiling value of -1.2743 is", num10);
fmt.Println("The ceiling value of -2.0001 is", num11);
}
Round the infinity using ceiling math method and print the resultant in console.
package main
import (
"fmt"
"math"
)
func main() {
// Positive ∞ infinite value
n := math.Inf(+1)
fmt.Println("The ceiling value of +Inf is", math.Ceil(n));
// Negative ∞ infinite value
m := math.Inf(-1)
fmt.Println("The ceiling value of -Inf is", math.Ceil(m));
}