mirror of
https://github.com/ACEmulator/ACE
synced 2026-08-17 12:26:06 -04:00
* moved order-insensitive "half-processing" earlier in packet processing pipeline added adaptive resiliency to CryptoSystem * undo untested assumption
34 lines
954 B
C#
34 lines
954 B
C#
namespace ACE.Common.Extensions
|
|
{
|
|
public static class DoubleExtensions
|
|
{
|
|
public static string FormatChance(this double chance)
|
|
{
|
|
if (chance == 1)
|
|
{
|
|
return "100%";
|
|
}
|
|
if (chance == 0)
|
|
{
|
|
return "0%";
|
|
}
|
|
double r = (chance * 100);
|
|
string p = r.ToString("F99").TrimEnd('0');
|
|
if (!p.StartsWith("0."))
|
|
{
|
|
int extra = 2;
|
|
if (p.IndexOf(".0") > -1 || p.EndsWith("."))
|
|
{
|
|
extra = 0;
|
|
}
|
|
return p.Substring(0, p.IndexOf('.') + extra) + "%";
|
|
}
|
|
int i = p.IndexOfAny(new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9' });
|
|
if (i < 0)
|
|
{
|
|
return "0%";
|
|
}
|
|
return p.Substring(0, i + 1) + "%";
|
|
}
|
|
}
|
|
}
|