Haruka
Haruka

Reputation: 1

how can I get 1000 decimal digits in C#?

Is it possible to get up to 1000 decimal digits in C#?

i need atleast 1000 decimal points of the value of pi for my program.

Upvotes: 0

Views: 2347

Answers (4)

Austin Henley
Austin Henley

Reputation: 4633

If you're still seeking an alternative to the other answers, check out the Bailey Borwein Plouffe formula for calculating the nth digit of Pi. You can use it to calculate the first 1000 digits.

enter image description here

Upvotes: 2

Cheng Chen
Cheng Chen

Reputation: 43531

Well you can use an array to simulate a number, for example, if you need to calcuate a(has 100000 digits) plus b(has 99999 digits):

 a:     a[100000]     a[99999]      a[99998]   ... a[1]           a[0]
+b:                   b[9999]       b[99998]   ... b[1]           b[0]
----------------------------------------------------------------------------
                                     ...   a[1]+b[1]+Carry      a[0]+b[0]

Upvotes: 3

Pete Baughman
Pete Baughman

Reputation: 3034

Yes, but not using the built in data types. Decimal is the best you can do and only has 28 to 29 significant digits.

You will need an arbitrary precision library, or you need to revisit your design and determine if you really need 1000 decimal digits.

If you are merely trying to calculate Pi out to 1000 digits, there are functions that you can use to calculate the nth digit of Pi. At that point, you can simply store the results in an Array

Upvotes: 2

Antimony
Antimony

Reputation: 39471

You need to use abritrary precision arithmetic. I'm not sure about native C# libraries, but GMP says it has a C# wrapper.

You can also use J#'s BigDecimal.

Here's a similar question.

Upvotes: 1

Related Questions