From f68a186bc92d1bc973b3e3588aea3fdd832e4bd1 Mon Sep 17 00:00:00 2001
From: Mira <56395159+TheXorog@users.noreply.github.com>
Date: Mon, 24 Apr 2023 14:49:29 +0200
Subject: [PATCH] feat: Added CalculatePercentage
---
UniversalExtensions.cs | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/UniversalExtensions.cs b/UniversalExtensions.cs
index 383a158..b59f75e 100644
--- a/UniversalExtensions.cs
+++ b/UniversalExtensions.cs
@@ -618,6 +618,26 @@ public static class UniversalExtensions
return "#" + R.ToString("X2") + G.ToString("X2") + B.ToString("X2");
}
+
+
+ ///
+ /// Calculates the percentage of the given 2 values.
+ ///
+ /// The current value.
+ /// The maximum value.
+ /// The percentage.
+ ///
+ public static int CalculatePercentage(double current, double max)
+ {
+ if (max == 0)
+ throw new ArgumentException("Max cannot be zero.");
+
+ double percentage = (current / max) * 100;
+ return Convert.ToInt32(percentage);
+ }
+
+
+
///
/// Shorten a string to the given length
///