I run these lines:
a = 0.833
SetPrecision[a, 20]
and this is the output:
0.833
0.83299999999999996270
I expected to receive
0.83300000000000000000
Do you have any suggestion? Thank you!
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI run these lines:
a = 0.833
SetPrecision[a, 20]
and this is the output:
0.833
0.83299999999999996270
I expected to receive
0.83300000000000000000
Do you have any suggestion? Thank you!
I suggest SetPrecision[833/1000 , 20]
or SetPrecision[.833 // Rationalize, 20]
.
SetPrecision[a,20]
is equivalent toN[FromDigits[RealDigits[a,2],2],20] = 0.83299999999999996270
. MMA works with binary numbers. $\endgroup$ – Alx Aug 25 '19 at 16:40a`20
is not syntactically valid. The problem is thata = 0.833
evaluates0.833
in machine precision binary and obtains the binary floating point number nearest to0.833
, but that number is only approximately equal to0.833
. $\endgroup$ – Michael E2 Aug 25 '19 at 20:34a'20
. Just usea=0.833'20
anda
will have 20 digits of precision from then on or until it is reassigned. That is supposed to be a back tick, but I can't write it that way because of the way comments treat back ticks. $\endgroup$ – Bill Watts Aug 25 '19 at 21:58