summaryrefslogtreecommitdiff
path: root/vendor/github.com/vbauerster/mpb/v7/internal/percentage.go
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2021-06-16 05:57:09 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2021-06-17 14:59:42 -0400
commitb6662eed3f27ac5466501b046db4f1608845af61 (patch)
tree7a4f80a77f812505a6261bc11ed8151235f903f1 /vendor/github.com/vbauerster/mpb/v7/internal/percentage.go
parent725b5001a17f703d95a3c88e4f58225c5290576b (diff)
downloadpodman-b6662eed3f27ac5466501b046db4f1608845af61.tar.gz
podman-b6662eed3f27ac5466501b046db4f1608845af61.tar.bz2
podman-b6662eed3f27ac5466501b046db4f1608845af61.zip
Vendor in containers/common v0.40.0
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'vendor/github.com/vbauerster/mpb/v7/internal/percentage.go')
-rw-r--r--vendor/github.com/vbauerster/mpb/v7/internal/percentage.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/vendor/github.com/vbauerster/mpb/v7/internal/percentage.go b/vendor/github.com/vbauerster/mpb/v7/internal/percentage.go
new file mode 100644
index 000000000..a8ef8be12
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v7/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))
+}