package main
import (
"fmt"
"math"
)
func roundTo(num float64, precision int) float64 {
scale := math.Pow(10, float64(precision))
return math.Round(num*scale) / scale
}
func main() {
bytes := 26
kb := float64(bytes) / 1000
fmt.Printf("Raw Value: %f KB\n", kb)
fmt.Printf("Rounded to 2 Decimal Places: %0.2f KB\n", roundTo(kb, 2))
}
To embed this program on your website, copy the following code and paste it into your website's HTML: