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

Tree @85db7c5 (Download .tar.gz)

percentage.go @85db7c5raw · 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))
}