Пример #1
0
    public string Abbrevs(BigDouble num)
    {
        string result;

        string[] Abbrevs = new string[] { "", "K", "M", "B", "T", "Qa", "Qi", "Sx", "Sp", "Oc", "No", "Dc", "Ud", "Dd", "Td", "Qad", "Qid", "Sxd", "Spd", "Ocd", "Nod", "Vg", "Uvg", "Dvg", "Tvg", "Qavg", "Qivg", "Sxvg", "Spvg", "Ocvg", "Novg", "Tg", "Utg", "Dtg", "Ttg", "Qatg", "Qitg", "Sxtg", "Sptg", "Octg", "Notg", "Qag", "Uqag", " qag", "Tqag", "Qaqag", "Qiqag", "Sxqag", "Spqag", "Ocqag", "Noqag", "Qig", "Uqig", " Dqig", " Tqig", "Qaqig", "Qiqig", "Sxqig", "Spqig", "Ocqig", "Noqig", "Sxg" };
        int      i;

        for (i = 0; i < Abbrevs.Length; i++)
        {
            if (num <= 999)
            {
                break;
            }
            else
            {
                num = BigDouble.Floor((num / 100f) / 10f);
            }
        }

        if (num == BigDouble.Floor((num)))
        {
            result = num.ToString() + Abbrevs[i];
        }
        else
        {
            result = num.ToString("F2") + Abbrevs[i];
        }
        return(result);
    }
Пример #2
0
    public static string GetAbbreviation(BigDouble exp)
    {
        // Example: e300
        exp = BigDouble.Floor(exp / 3) - 1; // Floor(300 / 3) - 1 = 99
        var index2 = 0;
        var prefix = new List <string> {
            StandardPrefixes[0][(int)exp % 10]
        };                                                                    // {"N"}

        // Start with 99
        // exp then becomes Floor(99/10) = 9
        // Add StandardPrefixes[1][9] = "Nn" to prefix. So prefix = {"N", "Nn"}
        // Since exp is 9, less than 10. We are done with the while loop. index2 is 1.
        while (exp >= 10)
        {
            exp = BigDouble.Floor(exp / 10);
            prefix.Add(StandardPrefixes[++index2 % 3][(int)exp % 10]);
            // ++index2 basically adds 1 to index2 before accessing it.
        }

        // index2 = Floor(1 / 3) = 0
        index2 = (int)BigDouble.Floor(index2 / 3);
        // prefix.Count = 2.
        // 3 - (2 % 3) = 1, so this while loop adds "" 1 time. prefix.Count is now 3.
        // Regardless of what occurs above, prefix.Count will always end up being 3.
        while (prefix.Count % 3 != 0)
        {
            prefix.Add("");
        }


        var ret = "";

        // index2 is 0.
        // First run: We add: prefix[0 * 3] + prefix[0 * 3 + 1] + prefix[0 * 3 + 2] + StandardPrefixes2[0] to ret,
        // which is: prefix[0] + prefix[1] + prefix[2] + StandardPrefixes2[0]
        // which is: "N" + "Nn" + "" + "" = "NNn"
        // We then subtract index2 by one by: StandardPrefixes2[index2--]
        // Since index2 < 0, the while loop stops.
        while (index2 >= 0)
        {
            ret += prefix[index2 * 3] + prefix[index2 * 3 + 1] + prefix[index2 * 3 + 2] + StandardPrefixes2[index2--];
        }

        // This occurs only with bigger numbers, most StandardPrefixes2 have a "-" at the end.
        // If ret has a "-" at the end, it will crop it by 1 character.
        if (ret.EndsWith("-"))
        {
            ret = ret.Slice(0, ret.Length - 1);
        }
        // After that, it will just replace a bumch of strings with new strings:
        return(ret.Replace("UM", "M").Replace("UNA", "NA").Replace("UPC", "PC").Replace("UFM", "FM"));
    }
Пример #3
0
    public static string Notate(this BigDouble number)
    {
        if (number < 1e6 && number > -1e6)
        {
            return(number.ToDouble().ToString("N0"));
        }

        switch (Notation)
        {
        case 0:     // Standard
            string numberString       = (number / BigDouble.Pow(10, 3 * BigDouble.Floor(number.exponent / 3))).ToString("F3");
            string abbreviationString = number.exponent < 303 ? StandardNotation[(int)((number.exponent - (number.exponent % 3)) / 3)] : GetAbbreviation(number.exponent);
            return(numberString + " " + abbreviationString);

        case 1:
            return("Science");
        }
        return("");
    }