当前位置: 首页>>代码示例>>C#>>正文


C# BigInteger.ToString方法代码示例

本文整理汇总了C#中System.Numerics.BigInteger.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.ToString方法的具体用法?C# BigInteger.ToString怎么用?C# BigInteger.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Numerics.BigInteger的用法示例。


在下文中一共展示了BigInteger.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FormatE1

        public void FormatE1()
        {
            var first = new BigInteger(123456789);
            Assert.AreEqual(first.ToString("E", CultureInfo.InvariantCulture), "1.234568E+008");
            Assert.AreEqual(first.ToString("e", CultureInfo.InvariantCulture), "1.234568e+008");

            Debug.Print("BigInteger Format First ok");

            var second = BigInteger.Parse("10000009000000001", CultureInfo.InvariantCulture);
            Assert.AreEqual(second.ToString("E", CultureInfo.InvariantCulture), "1.000001E+016");
            Assert.AreEqual(second.ToString("e", CultureInfo.InvariantCulture), "1.000001e+016");

            Debug.Print("BigInteger Format Second ok");

            var third = BigInteger.Parse("10000005000000001", CultureInfo.InvariantCulture);
            Assert.AreEqual(third.ToString("E", CultureInfo.InvariantCulture), "1.000001E+016");
            Assert.AreEqual(third.ToString("e", CultureInfo.InvariantCulture), "1.000001e+016");

            Debug.Print("BigInteger Format Third ok");

            var fourth = BigInteger.Parse("10000004000000001", CultureInfo.InvariantCulture);
            Assert.AreEqual(fourth.ToString("E", CultureInfo.InvariantCulture), "1.000000E+016");
            Assert.AreEqual(fourth.ToString("e", CultureInfo.InvariantCulture), "1.000000e+016");

            Debug.Print("BigInteger Format Fourth ok");

            var fifth = BigInteger.Parse("10000095000000001", CultureInfo.InvariantCulture);
            Assert.AreEqual(fifth.ToString("E", CultureInfo.InvariantCulture), "1.000010E+016");
            Assert.AreEqual(fifth.ToString("e", CultureInfo.InvariantCulture), "1.000010e+016");

            Debug.Print("BigInteger Format Fifth ok");
        }
开发者ID:mesheets,项目名称:Theraot-CF,代码行数:32,代码来源:BigIntegerTestEx.cs

示例2: FormatC

        public void FormatC()
        {
            var first = new BigInteger(123456789);
            Assert.AreEqual(first.ToString("C", CultureInfo.InvariantCulture), "¤123,456,789.00");
            Assert.AreEqual(first.ToString("c", CultureInfo.InvariantCulture), "¤123,456,789.00");
            Assert.AreEqual(first.ToString("C3", CultureInfo.InvariantCulture), "¤123,456,789.000");
            Assert.AreEqual(first.ToString("c3", CultureInfo.InvariantCulture), "¤123,456,789.000");

            Assert.AreEqual(first.ToString("C3", CultureInfo.GetCultureInfo("en-US")), "$123,456,789.000");
            Assert.AreEqual(first.ToString("c3", CultureInfo.GetCultureInfo("en-US")), "$123,456,789.000");

            Assert.AreEqual(first.ToString("C3", CultureInfo.GetCultureInfo("fr-FR")), "123\u00A0456\u00A0789,000 €");
            Assert.AreEqual(first.ToString("c3", CultureInfo.GetCultureInfo("fr-FR")), "123\u00A0456\u00A0789,000 €");

            Assert.AreEqual(first.ToString("C3", CultureInfo.GetCultureInfo("ja-JP")), "¥123,456,789.000");
            Assert.AreEqual(first.ToString("c3", CultureInfo.GetCultureInfo("ja-JP")), "¥123,456,789.000");

            var second = BigInteger.Parse("100000090000000010", CultureInfo.InvariantCulture);
            Assert.AreEqual(second.ToString("C", CultureInfo.InvariantCulture), "¤100,000,090,000,000,010.00");
            Assert.AreEqual(second.ToString("c", CultureInfo.InvariantCulture), "¤100,000,090,000,000,010.00");
            Assert.AreEqual(second.ToString("C3", CultureInfo.InvariantCulture), "¤100,000,090,000,000,010.000");
            Assert.AreEqual(second.ToString("c3", CultureInfo.InvariantCulture), "¤100,000,090,000,000,010.000");

            Assert.AreEqual(second.ToString("C3", CultureInfo.GetCultureInfo("en-US")), "$100,000,090,000,000,010.000");
            Assert.AreEqual(second.ToString("c3", CultureInfo.GetCultureInfo("en-US")), "$100,000,090,000,000,010.000");

            Assert.AreEqual(second.ToString("C3", CultureInfo.GetCultureInfo("fr-FR")), "100\u00A0000\u00A0090\u00A0000\u00A0000\u00A0010,000 €");
            Assert.AreEqual(second.ToString("c3", CultureInfo.GetCultureInfo("fr-FR")), "100\u00A0000\u00A0090\u00A0000\u00A0000\u00A0010,000 €");

            Assert.AreEqual(second.ToString("C3", CultureInfo.GetCultureInfo("ja-JP")), "¥100,000,090,000,000,010.000");
            Assert.AreEqual(second.ToString("c3", CultureInfo.GetCultureInfo("ja-JP")), "¥100,000,090,000,000,010.000");
        }
开发者ID:mesheets,项目名称:Theraot-CF,代码行数:32,代码来源:BigIntegerTestEx.cs

示例3: SaddyCopperOperation

        private static void SaddyCopperOperation(BigInteger number)
        {
            if (number.ToString().Length == 1 || numberOfTransformations == 10)
            {
                if (numberOfTransformations < 10)
                {
                    Console.WriteLine(numberOfTransformations);
                }

                Console.WriteLine(number);
                return;
            }
            numberOfTransformations++;

            List<int> listOfsums = new List<int>();
            while (number > 10)
            {
                number /= 10;
                List<int> digitsAtEvenPositions = new List<int>();
                for (int i = 0; i < number.ToString().Length; i += 2)
                {
                    digitsAtEvenPositions.Add(number.ToString()[i] - '0');
                }

                listOfsums.Add(digitsAtEvenPositions.Sum());
            }
            long product = 1;
            foreach (var num in listOfsums)
            {
                product *= num;
            }
            //Console.WriteLine(product);
            //--------------------------------
            SaddyCopperOperation(product);
        }
开发者ID:ViktorBarzin,项目名称:Telerik-Academy-2015-2016,代码行数:35,代码来源:Program.cs

示例4: Run

 public string Run()
 {
     BigInteger total = new BigInteger(0);
     for (int i = 1; i <= 1000; i++)
     {
         total += BigInteger.Pow(i, i);
     }
     return total.ToString().Substring(total.ToString().Length - 10);
 }
开发者ID:mikeswright49,项目名称:ProjectEuler,代码行数:9,代码来源:Problem48.cs

示例5: Main

        static void Main(string[] args)
        {
            ulong startNumber = ulong.Parse(Console.ReadLine());
            ulong endNumber = ulong.Parse(Console.ReadLine());
            string replacementString = Console.ReadLine();
            BigInteger sum = new BigInteger();

            string sumString = sum.ToString();

            //calculate sum of numbers
            for (ulong i = startNumber; i < endNumber; i++)
            {
                if (i % 5 == 0)
                {
                    sum += i;
                }
                else
                {
                    ulong mod = i % 5;
                    sum += mod;
                }
            }

            string replacedDigit;
            if (sum % 2 == 0)
            {
                for (int i = 0; i < sumString.Length; i++)
                {

                    replacedDigit = sum.ToString()[0].ToString();
                    replacedDigit = replacementString;

                    if (sumString[i].Equals(replacedDigit))
                    {
                        string newString = sumString[i].ToString();
                        newString = replacementString;
                    }
                }

            }
            else
            {
                for (int i = 0; i < sumString.Length; i++)
                {
                    replacedDigit = sum.ToString()[sum.ToString().Length - 1].ToString();
                    replacedDigit = replacementString;

                    if (sumString[i].Equals(replacedDigit))
                    {
                        string newString = sumString[i].ToString();
                        newString = replacementString;
                    }
                }
            }
            Console.WriteLine(sumString);
        }
开发者ID:LilyLazarova,项目名称:Basic-Level-Softuni,代码行数:56,代码来源:PetarsGame.cs

示例6: is_prime_MR

        private static bool is_prime_MR(BigInteger R, int num)
        {
            Random random = new Random();
            BigInteger s = 0;
            BigInteger t = R - 1;

            while (t % 2 == 0)
            {
                t = t / 2;
                s++;
            }

            String st = "";
            int p;
            int q = Int32.MaxValue;
            BigInteger A;
            BigInteger b;
            BigInteger i = 0;

            for (int j = 1; j <= num; j++)
            {
                p = random.Next(10);
                if (p % 2 == 0)
                    p = p + 1;
                st = p.ToString();
                while (st.Length <= R.ToString().Length - q.ToString().Length)
                {
                    st = random.Next(q) + st;
                }
                try
                {
                    st = random.Next(10 ^ (R.ToString().Length - st.Length - 2)) + st;
                }
                catch { }
                A = BigInteger.Parse(st);
                if (A.IsOne)
                    A++;
                if ((R % A).IsZero)
                    return false;
                b = BigInteger.ModPow(A, t, R);
                if (b.IsOne)
                    continue;
                i = 0;
                do
                {
                    b = BigInteger.ModPow(b, BigInteger.One + BigInteger.One, R);
                    i++;
                }
                while (!(b.IsOne || b.ToString() == (R - 1).ToString() || i > s));
                if (i > s)
                    return false;
            }

            return true;
        }
开发者ID:GarageInc,项目名称:all,代码行数:55,代码来源:Function.cs

示例7: Main

        static void Main(string[] args)
        {
            short n = 1000;
            var bi = new BigInteger();

            for (short i = 1; i <= n; i++)
                bi += Pow(i, i);

            Console.WriteLine(bi.ToString().Substring(bi.ToString().Length-10, 10));
            Console.ReadKey();
        }
开发者ID:rkazakov,项目名称:projecteuler.net,代码行数:11,代码来源:Problem48.cs

示例8: ConvertToArray

 private static int[] ConvertToArray(BigInteger num)
 {
     int[] digits = new int[num.ToString().Length];
     string number = num.ToString();
     BigInteger currentNumber = num;
     for (int i = number.Length - 1; i >= 0; i--)
     {
         digits[i] = (int)(currentNumber % 10);
         currentNumber /= 10;
     }
     return digits;
 }
开发者ID:StoyanDraganow,项目名称:Csharp_2_Homeworks,代码行数:12,代码来源:Program.cs

示例9: Calculate

 private void Calculate()
 {
     BigInteger res = new BigInteger();
     res = a + b;
     textBox3.Text = res.ToString();
     res = a * b;
     textBox4.Text = res.ToString();
     res = BigInteger.Pow(a, 2);
     textBox5.Text = res.ToString();
     res = BigInteger.ModPow(a, 1, b);
     textBox6.Text = res.ToString();
 }
开发者ID:oleksandrkin,项目名称:data-security,代码行数:12,代码来源:Form1.cs

示例10: ConvertToArray

 // Convert number of digit to array
 static int[] ConvertToArray(BigInteger num)
 {
     string digit = num.ToString();
     int[] digits = new int[num.ToString().Length];
     int count = 0;
     foreach (var item in digit)
     {
         digits[count] = item - '0';
         count++;
     }
     return digits;
 }
开发者ID:zivoroka,项目名称:TelerikAcademy,代码行数:13,代码来源:NumberAsArray.cs

示例11: IsLychrel

 static bool IsLychrel(BigInteger nn)
 {
     int attempts = 50;
     do
     {
         nn += BigInteger.Parse(Util.ReverseString(nn.ToString()));
         if (Util.IsPalindrome(nn.ToString()))
         {
             return false;
         }
     } while (attempts-- > 0);
     return true;
 }
开发者ID:jmonasterio,项目名称:projecteuler,代码行数:13,代码来源:Program.cs

示例12: CalculateProduct

        public static BigInteger CalculateProduct(BigInteger firstMultiplier, BigInteger secondMultiplier)
        {
            int n = firstMultiplier.ToString().Length;

            a = BigInteger.Parse(firstMultiplier.ToString().Substring(0, n / 2));
            b = BigInteger.Parse(firstMultiplier.ToString().Substring(n / 2));
            c = BigInteger.Parse(secondMultiplier.ToString().Substring(0, n / 2));
            d = BigInteger.Parse(secondMultiplier.ToString().Substring(n / 2));

            BigInteger ac = a * c;
            BigInteger bd = b * d;
            return BigInteger.Pow(10, n) * ac + BigInteger.Pow(10, n / 2) * ((a + b) * (c + d) - ac - bd) + bd;
        }
开发者ID:UlyanaShym,项目名称:AlgorithmsPrometheus,代码行数:13,代码来源:1_MethodKaratsuby.cs

示例13: FormatD

        public void FormatD()
        {
            var first = new BigInteger(123456789);
            Assert.AreEqual(first.ToString("D", CultureInfo.InvariantCulture), "123456789");
            Assert.AreEqual(first.ToString("d", CultureInfo.InvariantCulture), "123456789");
            Assert.AreEqual(first.ToString("D20", CultureInfo.InvariantCulture), "00000000000123456789");
            Assert.AreEqual(first.ToString("d20", CultureInfo.InvariantCulture), "00000000000123456789");

            var second = BigInteger.Parse("100000090000000010", CultureInfo.InvariantCulture);
            Assert.AreEqual(second.ToString("D", CultureInfo.InvariantCulture), "100000090000000010");
            Assert.AreEqual(second.ToString("d", CultureInfo.InvariantCulture), "100000090000000010");
            Assert.AreEqual(second.ToString("D20", CultureInfo.InvariantCulture), "00100000090000000010");
            Assert.AreEqual(second.ToString("d20", CultureInfo.InvariantCulture), "00100000090000000010");
        }
开发者ID:mesheets,项目名称:Theraot-CF,代码行数:14,代码来源:BigIntegerTestEx.cs

示例14: GetAnswer

        public override string GetAnswer()
        {
            BigInteger pectorial = new BigInteger(1);
            for (int i=1; i<=100; i++) {
                pectorial *= i;
            }

            int result = 0;
            foreach (char c in pectorial.ToString().ToArray()) {
                result += c - 48;
            }

            return string.Format("결과값 {0} 의 자리수를 모두 더한 값 : {1}", pectorial.ToString(), result);
        }
开发者ID:wksak,项目名称:ProjectEuler,代码行数:14,代码来源:Question0020.cs

示例15: ShortenCurrency

 public static string ShortenCurrency(this string String, BigInteger Currency)
 {
     if (Currency < 1000000) return Currency.ToString("#,##0");
     else
     {
         string currencyString = Currency.ToString();
         int currencyStringLength = currencyString.Length;
         double calculation = (currencyStringLength / 3d);
         int baseNumberLength = ((calculation == (int)calculation) ? 3 : (int)Math.Round((calculation - (int)calculation) * 3));
         string decimals = currencyString.Substring(baseNumberLength, Math.Min(3, (currencyStringLength - baseNumberLength))).TrimEnd('0');
         return String = (currencyString.Substring(0, baseNumberLength) +
            ((decimals.Length > 0) ? ("." + decimals) : null)
             + " " + CurrencyNames[(int)Math.Ceiling(calculation) - 3]);
     }
 }
开发者ID:DeanReynolds,项目名称:Nyan-Clicker,代码行数:15,代码来源:String.cs


注:本文中的System.Numerics.BigInteger.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。