Skip to main content

numerics - Mod[1.2, 0.2] is not equal to zero


Why doesn't the following expression evaluate to zero?


In[1]:=Mod[1.2, 0.2]
Out[1]=0.2

Edit:


This is what I wanted to do:


xgrid = Table[{i,If[Mod[i, 0.2] == 0 , GrayLevel[0.5], GrayLevel[0.8]]}, {i, 0, 1.5, 0.05}]

I haven't programmed in a while so I forgot this happens. It was probably an error due to floating point arithmetic (0.2 cannot be fully represented by binary digits) so this was my solution:



xgrid = Table[{i*0.05, If[Mod[i, 4] == 0 , GrayLevel[0.5], GrayLevel[0.8]]}, {i, 0, 30, 1}]

This may also be the reason this solution for plotting minor and major grid lines didn't work for me




Comments