package web import ( "math" "strconv" ) // trimPercent cuts v to digits decimals instead of rounding, so 99.9996 // never reads as a perfect 100. The epsilon absorbs float noise such as // 99.12 being stored as 99.1199999. func trimPercent(v float64, digits int) string { scale := math.Pow(10, float64(digits)) v = math.Floor(v*scale+1e-6) / scale return strconv.FormatFloat(v, 'f', digits, 64) + "%" }