summaryrefslogtreecommitdiff
path: root/vendor/github.com/vbauerster/mpb/internal/percentage.go
blob: 0483d25986512b13f20d945551079b0ec51284bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
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))
}