I'm trying to generating a list of numbers with the function table. But it caused a little deviation which I didn't expect. Let's say I need a function like:


The result I expected was {0.1, 0.3, 0.5, 0.7, 0.9}. It gave me a very similar output. But if I want to copy the second part of the output, I suddenly realized that the second part was not exactly 0.3. It was 0.30000000000000004`. Does anybody know what happened and how can I avoid this?


closed as off-topic by Bob Hanlon, m_goldberg, MarcoB, WReach, user9660 Feb 15 '16 at 5:41

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Bob Hanlon, m_goldberg, MarcoB, WReach, Community
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Table[i, {i, 1/10, 1, 1/5}] $\endgroup$ – thedude Feb 14 '16 at 18:58
  • $\begingroup$ Hey it really works! Why does it happen? $\endgroup$ – 407Peezy Feb 14 '16 at 19:06
  • 2
    $\begingroup$ This is caused by the fact that many decimal numbers with a finite number of digits cannot be exactly represented by binary numbers with a finite number of digits. For instance, 0.1 (dec) is the infinitely repeating series of 1, 1, 0, 0 in binary. Since you can't have infinite series of digits some capping needs to take place, leading to small representational errors. $\endgroup$ – Sjoerd C. de Vries Feb 14 '16 at 19:10
  • $\begingroup$ From documentation: "When any number in an arithmetic expression is given with an explicit decimal point, you get an approximate numerical result for the whole expression." reference.wolfram.com/language/tutorial/… $\endgroup$ – thedude Feb 14 '16 at 19:10

Browse other questions tagged or ask your own question.