How to calculate the absolute value of a number in Go?

In Go, you can calculate the absolute value of a number using the math package. Here's an example:

package main import ( "fmt" "math" ) func main() { num := -5 absNum := math.Abs(float64(num)) fmt.Println(absNum) }

In this example, we use the math.Abs() function to calculate the absolute value of the num variable. Note that math.Abs() takes a float64 argument, so we need to convert the number to a float64 using float64(num) in order to use it. The result is then printed using fmt.Println().