ace/Source/ACE.Common/Extensions/DoubleExtensions.cs
fartwhif 90e328660c move order-insensitive items earlier in packet processing pipeline (#1647)
* moved order-insensitive "half-processing" earlier in packet processing pipeline
added adaptive resiliency to CryptoSystem

* undo untested assumption
2019-04-06 00:52:07 -05:00

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) + "%";
}
}
}