+ 1

Help

How to write a program in python to find a value of pi number (input) of times decimals we want?

30th Jul 2024, 6:49 PM
Rahul Bankar
Rahul Bankar - avatar
4 Answers
30th Jul 2024, 9:44 PM
Chris Coder
Chris Coder - avatar
+ 2
You can achieve up to 15 decimals by string slicing the math.pi constant.
31st Jul 2024, 12:11 AM
Brian
Brian - avatar
+ 2
Rahul Bankar , please provide a sample that demonstrates what you are looking for.
31st Jul 2024, 3:56 PM
Lothar
Lothar - avatar
+ 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
1st Aug 2024, 2:36 PM
Š‘Š¾Ń€ŠøсŠµŠ½ŠŗŠ¾ Š˜Š²Š°Š½ Š˜Š²Š°Š½Š¾Š²Šøч