Go Floor()
Published Jul 16, 2023
Contribute to Docs
The Floor() function returns a given decimal number rounded down to the nearest whole number.
Syntax
math.Floor(decimalNumber)
The Floor() function accepts a single parameter of type float64 and rounds it down to the nearest whole number.
Note: The returned value may appear to be an
int, but it is afloat64value.
Note: Passing any of the following values:
±Inf,±0, andNaNas an argument to theFloor()function, will result in the returned value being the same as the argument.
Example
The following example demonstrates how to use the Floor() function to round down numbers and print the result:
package mainimport("fmt""math")func main() {float_number1 := 8.99float_number2 := -3.11exp_case := math.NaN()floored_number1 := math.Floor(float_number1)floored_number2 := math.Floor(float_number2)floored_number3 := math.Floor(exp_case)fmt.Println("The floored value of 8.99 is:", floored_number1)fmt.Println("The floored value of -3.11 is:", floored_number2)fmt.Print("The floored value of NaN is:", floored_number3)}
The output will be:
The floored value of 8.99 is: 8The floored value of -3.11 is: -4The floored value of NaN is: NaN
Codebyte Example
The provided example is executable and demonstrates the usage of the Floor() function.
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