2

I'm looking for some data type what to use in C# .NET for storing very big decimal number in range <0;1) eg. 1000 decimals (as much as possible, the more is better). I will need to use this number for basic mathematical operations (+, -, *, /, <, >). Data type decimal is too small for me. I know BigInteger, but it is not for decimal number and it's operations.

Thank you for any help.

Banana Cake
  • 1,172
  • 1
  • 12
  • 31
  • Just use BigDecimal and put a "0." at the front. Or build your own. – Kent Kostelac Nov 18 '17 at 17:51
  • 1
    Possible duplicate of [Arbitrary precision decimals in C#?](https://stackoverflow.com/questions/621684/arbitrary-precision-decimals-in-c) – Ňuf Nov 18 '17 at 18:37

1 Answers1

2

There's nothing in the BCL for it.

However, I've found a custom built type that looks quite interesting called BigFloat. I've had a scan through the code and it looks quite good. It takes a BigInteger as the denominator so that should give you much greater accuracy.

It also covers your add, subtract, multiplation and so on. It even goes into square root/logarithms etc.

Here it is: https://github.com/Osinko/BigFloat

I'd take a look and see if it fits your purpose, there's an example in the repository.

Michael Clark
  • 462
  • 5
  • 17