summaryrefslogtreecommitdiff
path: root/vendor/github.com/vbauerster/mpb/v5/internal/percentage.go
blob: e321e0a6b5634e123e282668c61d8a16efdebfc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package internal

import "math"

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

func PercentageRound(total, current int64, width int) float64 {
	return math.Round(Percentage(total, current, width))
}