+ 1
Help
How to write a program in python to find a value of pi number (input) of times decimals we want?
4 Answers
+ 2
You may find this helpful.
https://www.geeksforgeeks.org/value-of-pi-up-to-50-decimal-places/
+ 2
You can achieve up to 15 decimals by string slicing the math.pi constant.
+ 2
Rahul Bankar ,
please provide a sample that demonstrates what you are looking for.
+ 1
To calculate Ļ to a specific number of decimal places in Python, you can use the mpmath library, which supports arbitrary-precision arithmetic.Here is an example code
from mpmath import mp
def calculate_pi(decimal_places):
mp.dps = decimal_places + 1 # +1 to account for the integer part of pi
pi_value = mp.pi
return str(pi_value)
decimal_places = int(input("Enter the number of decimal places: "))
print(calculate_pi(decimal_places))
It is also explained here:
https://stackoverflow.com/questions/45416626/print-pi-to-a-number-of-decimal-places