Esempio n. 1
0
    /// <summary>
    /// Shorten number to a specific length by replace additional length by Greek letter
    /// </summary>
    /// <param name="value">number want to short</param>
    /// <param name="length">maximum length allowed</param>
    /// <param name="format">whether to format return string</param>
    /// <returns>shortened string (i.e 1000 -> 1K)</returns>
    public static string Shorten(double value, int length, bool format = true)
    {
        int index = 0;

        while (Math.Round(value, 2).ToString().Replace(".", "").Length > length)
        {
            if (value >= 1000)
            {
                value /= 1000;
                index++;
            }
            else
            {
                break;
            }
        }
        StringFast stringFast = new StringFast();

        if (format)
        {
            stringFast.Append(Math.Round(value, 2, MidpointRounding.ToEven).ToString("#,#.#"));
        }
        else
        {
            stringFast.Append(Math.Round(value, 2));
        }
        return(stringFast.Append(_MetricPrefix[index]).ToString());
    }
Esempio n. 2
0
    public static string random(this string str, int length)
    {
        string     b  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        StringFast sf = new StringFast(length);

        for (int i = 0; i < length; i++)
        {
            sf.Append(b[UnityEngine.Random.Range(0, b.Length - 1)].ToString());
        }
        return(sf.ToString());
    }