How to convert degrees to radians and radians to degrees in Go?

To convert degrees to radians, you can use the formula:

radians = degrees * (π / 180)

Here's an example function in Go that converts degrees to radians:

package main import ( "fmt" "math" ) func degreesToRadians(degrees float64) float64 { return degrees * (math.Pi / 180) } func main() { degrees := 45.0 radians := degreesToRadians(degrees) fmt.Printf("%.2f degrees = %.2f radians\n", degrees, radians) }

To convert radians to degrees, you can use the formula:

degrees = radians * (180 / π)

Here's an example function in Go that converts radians to degrees:

package main import ( "fmt" "math" ) func radiansToDegrees(radians float64) float64 { return radians * (180 / math.Pi) } func main() { radians := math.Pi / 4 degrees := radiansToDegrees(radians) fmt.Printf("%.2f radians = %.2f degrees\n", radians, degrees) }

You can adjust the precision of the output by using the fmt.Printf function with the desired format specifier (e.g., %.2f for 2 decimal places).