To take the floor of a number in Go, we can use the math.Floor
function. This function takes a float64 as input and returns the largest integer value less than or equal to the input.
Here's an example of using math.Floor
:
main.go135 chars13 lines
In this example, we import the math
package, which provides a variety of mathematical functions. We then use the math.Floor
function to find the largest integer less than or equal to x
, and store the result in y
. Finally, we print the value of y
to the console.
Note that math.Floor
returns a float64 value, so if you need an integer result, you can convert the result using a type cast:
main.go52 chars3 lines
gistlibby LogSnag