feat: Added CalculatePercentage
This commit is contained in:
parent
f53ce5d067
commit
f68a186bc9
1 changed files with 20 additions and 0 deletions
|
|
@ -618,6 +618,26 @@ public static class UniversalExtensions
|
||||||
return "#" + R.ToString("X2") + G.ToString("X2") + B.ToString("X2");
|
return "#" + R.ToString("X2") + G.ToString("X2") + B.ToString("X2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the percentage of the given 2 values.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="current">The current value.</param>
|
||||||
|
/// <param name="max">The maximum value.</param>
|
||||||
|
/// <returns>The percentage.</returns>
|
||||||
|
/// <exception cref="ArgumentException"></exception>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Shorten a string to the given length
|
/// Shorten a string to the given length
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue