0

Is it possible to get more decimal precision than the decimal type in C#? According to MSDN, the decimal type can store up to 29 significant digits, however I am wondering if it possible to store more than that and how to go about doing so.

Thanks in advance.

Adam P
  • 4,603
  • 6
  • 31
  • 40
  • 1
    possible duplicate of [Big numbers with fraction support](http://stackoverflow.com/questions/2533960/big-numbers-with-fraction-support) - Has useful links in the answers. –  Jul 25 '10 at 02:36

3 Answers3

1

Sure - you can come up with your own data type (or use an existing third party library - the J++ runtime has an implementation of BigDecimal usable from C#).

What do you need that for? It is VERY unusual to need more than 29 significant digits ;)

TomTom
  • 61,059
  • 10
  • 88
  • 148
  • This question is more theoretical then practical. Recently I was trying to write a program to write Pi to a certain number of decimal places and I realized that I could only store up to 29 decimal places. Thus this question was born. – Adam P Jul 25 '10 at 02:39
  • Yeah. Mathematical playing is pretty much the only real use ;) – TomTom Jul 25 '10 at 02:53
0

You could use BigRational class in BCL. However It's still in beta version ...

SepehrM
  • 1,087
  • 2
  • 20
  • 44
0

You can use a scaled BigInteger if you're using 4.0. That will make arithmetic easier.

recursive
  • 83,943
  • 34
  • 151
  • 241