I need to display a number, let's say 0.9 exact at least until 17 decimal places. Even if I use Decimal or mpf, it gives me the result as if I would not be using them at all.
from mpmath import mpf
from decimal import Decimal
from decimal import getcontext
import mpmath
getcontext().prec = 25
mpmath.mp.prec=100
a=mpf("0.9")
b=mpf(0.9)
c=Decimal("0.9")
d=Decimal(0.9)
e=0.9
print("%.17f" % a)
print("%.17f" % b)
print("%.17f" % c)
print("%.17f" % d)
print("%.17f" % e)
The output is
>>0.90000000000000002
>>0.90000000000000002
>>0.90000000000000002
>>0.90000000000000002
>>0.90000000000000002
I have searched everywhere, but I can not seem to find aa solution. Is it even possible to get that precision? What I understood from mpf, they claim a much higher precision than I am getting. What am I missing?
Edited:
I am sorry for a potential misunderstanding, but what I really had in mind, is that I need to perform actual calculations with this number, not only to display it properly.