aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/vbauerster/mpb/v4/internal
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/vbauerster/mpb/v4/internal')
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/internal/percentage.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/vendor/github.com/vbauerster/mpb/v4/internal/percentage.go b/vendor/github.com/vbauerster/mpb/v4/internal/percentage.go
new file mode 100644
index 000000000..7e261cb22
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/internal/percentage.go
@@ -0,0 +1,15 @@
+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
+ }
+ return float64(int64(width)*current) / float64(total)
+}
+
+func PercentageRound(total, current int64, width int) float64 {
+ return math.Round(Percentage(total, current, width))
+}