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

Tree @f85a14a (Download .tar.gz)

percentage.go @f85a14araw · history · blame

package internal

import "math"

// 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(math.Round(p))
}