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 ///