Golang math.Floor - Syntax
mixed floor(mixed n);
The math.Floor() function in Golang is used to return the next lowest integer value (i.e. last largest integer not greaterthan the inputed value) by rounding up value if necessary.
mixed floor(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 floor math method and print the resultant in console.
package main
import (
"fmt"
"math"
)
func main() {
var num1 = math.Floor(1.0)
var num2 = math.Floor(1.1)
var num3 = math.Floor(1.2)
var num4 = math.Floor(1.3)
var num5 = math.Floor(1.4)
var num6 = math.Floor(1.5)
var num7 = math.Floor(1.6)
var num8 = math.Floor(1.7)
var num9 = math.Floor(1.8)
var num10 = math.Floor(1.9)
var num11 = math.Floor(2.0)
fmt.Println("The floor value of 1.0 is", num1);
fmt.Println("The floor value of 1.1 is", num2);
fmt.Println("The floor value of 1.2 is", num3);
fmt.Println("The floor value of 1.3 is", num4);
fmt.Println("The floor value of 1.4 is", num5);
fmt.Println("The floor value of 1.5 is", num6);
fmt.Println("The floor value of 1.6 is", num7);
fmt.Println("The floor value of 1.7 is", num8);
fmt.Println("The floor value of 1.8 is", num9);
fmt.Println("The floor value of 1.9 is", num10);
fmt.Println("The floor value of 2.0 is", num11);
}
Round the positive floating point number (random numbers) using floor math method and print the resultant in console.
package main
import (
"fmt"
"math"
)
func main() {
var num1 = math.Floor(1.5698)
var num2 = math.Floor(1.3093)
var num3 = math.Floor(1.0087)
var num4 = math.Floor(1.1038)
var num5 = math.Floor(1.9573)
var num6 = math.Floor(1.7462)
var num7 = math.Floor(1.6427)
var num8 = math.Floor(1.4128)
var num9 = math.Floor(1.8099)
var num10 = math.Floor(1.2743)
var num11 = math.Floor(2.0001)
fmt.Println("The floor value of 1.5698 is", num1);
fmt.Println("The floor value of 1.3093 is", num2);
fmt.Println("The floor value of 1.0087 is", num3);
fmt.Println("The floor value of 1.1038 is", num4);
fmt.Println("The floor value of 1.9573 is", num5);
fmt.Println("The floor value of 1.7462 is", num6);
fmt.Println("The floor value of 1.6427 is", num7);
fmt.Println("The floor value of 1.4128 is", num8);
fmt.Println("The floor value of 1.8099 is", num9);
fmt.Println("The floor value of 1.2743 is", num10);
fmt.Println("The floor value of 2.0001 is", num11);
}
Round the negative floating point number (random numbers) using floor math method and print the resultant in console.
package main
import (
"fmt"
"math"
)
func main() {
var num1 = math.Floor(-1.5698)
var num2 = math.Floor(-1.3093)
var num3 = math.Floor(-1.0087)
var num4 = math.Floor(-1.1038)
var num5 = math.Floor(-1.9573)
var num6 = math.Floor(-1.7462)
var num7 = math.Floor(-1.6427)
var num8 = math.Floor(-1.4128)
var num9 = math.Floor(-1.8099)
var num10 = math.Floor(-1.2743)
var num11 = math.Floor(-2.0001)
fmt.Println("The floor value of -1.5698 is", num1);
fmt.Println("The floor value of -1.3093 is", num2);
fmt.Println("The floor value of -1.0087 is", num3);
fmt.Println("The floor value of -1.1038 is", num4);
fmt.Println("The floor value of -1.9573 is", num5);
fmt.Println("The floor value of -1.7462 is", num6);
fmt.Println("The floor value of -1.6427 is", num7);
fmt.Println("The floor value of -1.4128 is", num8);
fmt.Println("The floor value of -1.8099 is", num9);
fmt.Println("The floor value of -1.2743 is", num10);
fmt.Println("The floor value of -2.0001 is", num11);
}
Round the infinity using floor 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 floor value of +Inf is", math.Floor(n));
// Negative ∞ infinite value
m := math.Inf(-1)
fmt.Println("The floor value of -Inf is", math.Floor(m));
}