11 lines
291 B
Go

package helpers
// ClampPct divides two floats and clamps them to the given limits. Provides
// divide-by-zero protection by just returning 0.
func ClampPct(num, denom, minimum, maximum float64) float64 {
if denom == 0 {
return 0
}
return max(minimum, min(maximum, (num/denom)*100))
}