# System.Numeric.BigInteger

• ### Question

• Is it possible to display a decimal value with the BigInteger class. I thought by maybe using BigInteger.Parse(string, NumberStyle) would work but it doesnt. Any help?
Tuesday, December 15, 2009 3:43 AM

• Thank you for the response. But the following throws an exception.

The BigInteger class is for integers.  Karel's code is correct and has no errors with valid arguments.
Tuesday, December 15, 2009 7:51 AM
• Ok. well thank you for clarifying that for me. But I understand that Karels answer may have been correct in scope with that fact, but was not correct in the scope of my question. The correct answer would been, you simply cant. So I have no idea why karels answer, was marked as the correct answer for all it did was show how to get an integer value, when I ask for double.
Tuesday, December 15, 2009 5:59 PM

### All replies

• Parse is for reading values. For displaying use ToString. Decimal is the default.
```using System;
using System.Numerics;
class HelloWorld
{
static void Main(string [] args)
{
BigInteger i = BigInteger.Parse(args[0]);
BigInteger j = BigInteger.Parse(args[1]);
Console.WriteLine("  {0}", i);
Console.WriteLine("+ {0}", j);
Console.WriteLine("= {0}", i + j);
}
}
```

-Karel
Tuesday, December 15, 2009 4:00 AM
• Thank you for the response. But the following throws an exception.
```BigInteger
i = BigInteger.Parse("2.2");
BigInteger j = BigInteger.Parse("4.8");
Console.WriteLine(" {0}", i);
Console.WriteLine("+ {0}", j);
Console.WriteLine("= {0}", i + j);```
Tuesday, December 15, 2009 4:08 AM
• Thank you for the response. But the following throws an exception.

The BigInteger class is for integers.  Karel's code is correct and has no errors with valid arguments.
Tuesday, December 15, 2009 7:51 AM
• That's correct - BigInteger is not for real numbers - see the docs http://msdn.microsoft.com/en-us/library/system.numerics.biginteger(VS.100).aspx

-Karel
Tuesday, December 15, 2009 8:19 AM
• Ok. well thank you for clarifying that for me. But I understand that Karels answer may have been correct in scope with that fact, but was not correct in the scope of my question. The correct answer would been, you simply cant. So I have no idea why karels answer, was marked as the correct answer for all it did was show how to get an integer value, when I ask for double.
Tuesday, December 15, 2009 5:59 PM
• Is it possible to display a decimal value with the BigInteger class. I thought by maybe using BigInteger.Parse(string, NumberStyle) would work but it doesnt. Any help?

For farther clarification from Karel's link:

using System;

using System.Numerics;

namespace ConsoleApplication4

{

class Program

{

static void Main(string [] args)

{

Decimal dec = new decimal(2.2);

BigInteger i = new BigInteger(dec);

dec = new decimal(4.8);

BigInteger j = new BigInteger(dec);

Console.WriteLine("  {0}", i);

Console.WriteLine("+ {0}", j);

Console.WriteLine("= {0}", i + j);

double dbl = 2.2d;

i = new BigInteger(dbl);

dbl = 4.8d;

j = new BigInteger(dbl);

Console.WriteLine("  {0}", i);

Console.WriteLine("+ {0}", j);

Console.WriteLine("= {0}", i + j);