My numerical calculation gives a list of numbers
list = {-0.36, 0.2499999999999992, -0.21, 0.36, 0.36}
,
I want to delete 0.25
which appears as 0.2499999999999992
in the list due to the numerical process. How can I remove such a number? I tried
DeleteCases[Chop@list, {0.25}]
but did not work.
0.25
or other numbers such as0.149999999999992
? For example, what is the desired output oflist2 = {-0.36, 0.2499999999999992, -0.21, 0.36, 0.36, 0.25, 0.149999999999992}
? $\endgroup$0.25
e.x0.2499999999999991
,0.2499999999999992
, or exactly0.25
. It would be nice also if the new listlist2
also showed only a few significant numbers say 4 such that0.149999999999992
becomes0.15
$\endgroup$In[226]:= list = {-0.36, 0.2499999999999992, -0.21, 0.36, 0.36}; DeleteCases[list, vv_ /; Abs[vv - 1/4] < 1/1000] Out[227]= {-0.36, -0.21, 0.36, 0.36} In[229]:= ResourceFunction["Discard"][list, Abs[# - 1/4] < 1/1000 &] Out[229]= {-0.36, -0.21, 0.36, 0.36}
$\endgroup$