diff options
Diffstat (limited to '')
-rw-r--r-- | dependencies/pkg/mod/github.com/vbauerster/mpb/v6@v6.0.4/internal/percentage.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/dependencies/pkg/mod/github.com/vbauerster/mpb/v6@v6.0.4/internal/percentage.go b/dependencies/pkg/mod/github.com/vbauerster/mpb/v6@v6.0.4/internal/percentage.go new file mode 100644 index 0000000..a8ef8be --- /dev/null +++ b/dependencies/pkg/mod/github.com/vbauerster/mpb/v6@v6.0.4/internal/percentage.go @@ -0,0 +1,19 @@ +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) +} + +// PercentageRound same as Percentage but with math.Round. +func PercentageRound(total, current int64, width int) float64 { + return math.Round(Percentage(total, current, width)) +} |