golang round float to number of digits

package main

import (
    "fmt"
    "math"
)

func roundToDigits(num float64, digits int) float64 {
    scale := math.Pow(10, float64(digits))
    return math.Round(num*scale) / scale
}

func main() {
    number := 3.14159265359
    roundedNumber := roundToDigits(number, 3)
    fmt.Printf("Original number: %f\n", number)
    fmt.Printf("Rounded to 3 digits: %f\n", roundedNumber)
}