0

I have calculation statement in C# as below statement:

(-0.0116 * (5.08 - 0.52 * Math.Pow(5.08, 1.3)) * Math.Pow(0.5, 1.1) * (-0.14 * Math.Pow((19000 * 0.5), 0.8)))

When I debug and add this statement to watch, it was shows as below screenshot:

enter image description here

but when assign to double variable, the result was changed:

enter image description here

How do I get 0.89713135944117184 without changing any of the implementation?

Community
  • 1
  • 1
user1219310
  • 732
  • 1
  • 9
  • 23

1 Answers1

0

The maximum precision of a double in C# is 15 or 16 digits. See the reference here.

You should use BigInteger, assuming you are using .Net 4+. BigInteger "Represents an arbitrarily large signed integer." See the BigInteger documentation here.

See this answer for an example implementation that uses the BigInteger class to do decimal based calculations.

Community
  • 1
  • 1
Oren Hizkiya
  • 4,420
  • 2
  • 23
  • 33