It has to do with the floating-point representation and how Matlab displays such numbers for readability. If you add this line to the end of your code:
sprintf('%22.20f',val)
you'll get:
ans =
0.00499999999999999924
Edit
Even though it technically deals with Python, this website offers a brief and concise overview on the limitations of floating-point representations.