Integer functions of square and square roots
4 answers
If your return value is a float, you can use Ceil or Floor from the math package and then convert it to int.
n := 5.5
o := math.Floor(n)
p := int(math.Pow(o, 2))
fmt.Println("Float:", n)
fmt.Println("Floor:", o)
fmt.Println("Square:", p)
5.5
5
25
Keep in mind that Floor still returns float64, so you'll want to wrap it in int () anyway
+2
source to share