C# High double precision

前端 未结 6 1480
我在风中等你
我在风中等你 2021-01-19 00:45

I\'m writing a function that calculates the value of PI, and returns it as a double. So far so good. But once the function gets to 14 digits after the decimal place, it can\

6条回答
  •  余生分开走
    2021-01-19 01:10

    How much precision do you need?

    Using decimal will give you roughly 28 decimal places:

    decimal pi = 3.14159265358979323846264338327950288419716939937510m;
    Console.WriteLine(pi);    // 3.1415926535897932384626433833
    

    If that's not enough for you then you'll need to search for some sort of BigDecimal implementation, or look at other techniques for performing the calculation.

提交回复
热议问题