+ 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?
3 Réponses
+ 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 😊
+ 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 ;)
0
This is my new version. Thank you for your help!
https://code.sololearn.com/cyZMwmydaDY2/?ref=app