+ 2
How to get more exact Pi constant?
Pi number is a Math class constant variable. In C# Pi is double type. Max digits of double is 14. So Pi = 3,14159265358979. For example somebody wants get 30 digits. Is it possible in c#?
6 Respostas
+ 2
You should use decimal.and executed a const for pi with 30 digits . Then use it every where you want .
+ 4
Doubles have 15-16 digits of precision.
Decimals have 28-29:
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/floating-point-types-table
30 seems to be just out of range.
This would be easy enough to test; try setting 30 total digits and see if the last digit changes on any value 0-9.
Edit: Note, the 29th digit is also likely to be unreliable.
+ 3
You should use decimal.and executed a const for pi with 30 digits . Then use it every where you want .
const decimal pi = (pi in 30 digits);
(you can find pi in internet)
+ 2
i think you can do it easily by constant decimal
0
thanks for answer Zahra Mohkami but what if I need 300 digits or 1000? It will take a lot of space of programm code. You give me direction to thinking. I will calculate pi and put it into decimal variable.