BigIntger给出包含十进制输入的错误

时间:2016-10-01 09:48:05

标签: c#

我为大整数输入编写了一个可能包含十进制值的代码。我为此选择了bigInt方法,但这不接受带小数值的输入

{
  Console.WriteLine("Enter Your first number :");
  BigInteger bigInt1 = BigInteger.Parse(Console.ReadLine());
  Console.WriteLine("Enter Your Second number :");
  BigInteger bigInt2 = BigInteger.Parse(Console.ReadLine());
  BigInteger sum = bigInt1 + bigInt2;
  Console.WriteLine("Result after adding two Bumbers is :" + "\t" + sum);
}

1 个答案:

答案 0 :(得分:-2)

您应该像这样使用Convert.ToInt64,首先转换Console.ReadLine()中的字符串,然后将其解析为decimal

{
  Console.WriteLine("Enter Your first number :");
  var input = Console.ReadLine();
  var num = Decimal.Parse(input);
  BigInteger bigInt1 = Convert.ToInt64(num);
}