Converting a string into BigInteger

后端 未结 2 864
悲&欢浪女
悲&欢浪女 2021-01-17 17:29

I have the following code that creates a very big number (BigInteger) which is converted then into a string.

// It\'s a console app         


        
2条回答
  •  一生所求
    2021-01-17 17:58

    Use BigInteger.Parse() method.

    Converts the string representation of a number in a specified style to its BigInteger equivalent.

    BigInteger bi = 2;
    for(int i = 0; i < 1234; i++)
    {
        bi *= 2;
    }
    
    var myBigIntegerNumber = bi.ToString();
    Console.WriteLine(BigInteger.Parse(myBigIntegerNumber));
    

    Also you can check BigInteger.TryParse() method with your conversation is successful or not.

    Tries to convert the string representation of a number to its BigInteger equivalent, and returns a value that indicates whether the conversion succeeded.

提交回复
热议问题