# Truncating digits after calculation

I am working on numerical solutions to PDEs. I get some outputs which I then place back into the original equation to check my answers against expected values which are the original inputs. The results look good if I print check value next to the expected value but can sometimes result in FALSE results when tested as follows (f3==f3chk). f1 is an original input point value like 2.6 for example while f1chk might come back as 2.60000000000003694822225952521 if I ask it to display all these digits. This difference is enough to cause the equality test to fail. My question: Is there a simple way to cut off all the trailing numbers beyond 6, not just in the display but but the memory itself. I've been looking through the documentation but nothing is so obvious. I could take the difference between the two values, test the its magnitude, and if its small enough, subtract it from the check value and then proceed with the equality test. This sound like a lot of rigamarole, and I would hope mathematica would have taken care of it somewhere.

• a = N[2.60000000000003694822225952521, 6] truncates the actual number. Commented Jan 30, 2020 at 20:34
• Sorry, I meant f3 where it says f1. Commented Jan 30, 2020 at 20:36
• This general link may be of use to you. Commented Jan 30, 2020 at 21:33
• Thanks Bill, This was helpful. I found that I also needed to use SetPrecision[] to get the desired result. I now have it working in a simple test notebook. Commented Jan 30, 2020 at 22:23
• Related: (7871), (55292) Commented Jan 30, 2020 at 22:39

An alternative to SetAccuracy is the following also

2.60000000000003694822225952521 // SetPrecision[#, 2] &


You can use SetAccuracy:

myvalue = 2.60000000000003694822225952521
SetAccuracy[myvalue, 2]


Out[801]= 2.6000000000000369482222595252

Out[802]= 2.6