I want to display a lot of decimals in python but i don't know how to display more than 50 decimals, can anyone help? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I want to display a lot of decimals in python but i don't know how to display more than 50 decimals, can anyone help?

https://code.sololearn.com/cn8gwZeRU14F/?ref=app

7th Nov 2018, 6:37 PM
Tibbe
Tibbe - avatar
3 Answers
+ 7
num2/num1 is a float, which you're then converting into decimal. So all the issues with floats would still remain. Do this instead: decimal.Decimal(num2) /decimal.Decimal(num1) Also, to get more decimal places, use this: decimal.getcontext().prec = 100 Hope that helps 😊
7th Nov 2018, 6:52 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 6
You're welcome, Tibbe . By the way, when you divide two decimal.Decimal numbers, they remain in that class. What I'm trying to say is, you could just do print(decimal.Decimal(num2) / decimal.Decimal(num1)) Also, since you asked for suggestions, you could directly write num1, num2 = num2, num1+num2 and skip line 17 ;)
7th Nov 2018, 7:15 PM
Kishalaya Saha
Kishalaya Saha - avatar
0
This is my new version. Thank you for your help! https://code.sololearn.com/cyZMwmydaDY2/?ref=app
7th Nov 2018, 7:07 PM
Tibbe
Tibbe - avatar