Codebase list golang-github-vbauerster-mpb / e17ac3d internal / percentage.go
e17ac3d

Tree @e17ac3d (Download .tar.gz)

percentage.go @e17ac3draw · history · blame

package internal

// Percentage is a helper function, to calculate percentage.
func Percentage(total, current, width int64) int64 {
	if total <= 0 {
		return 0
	}
	p := float64(width*current) / float64(total)
	return int64(Round(p))
}