What you are seeing is the machine precision. Machine Precision for floating number is roughly 16 digits. You can do arbitrary precision in Mathematica if you need it. For example,
There are ways to deal with numerical precision depending on what you want/need. For example you can use 20 digits of precision if it makes sense. Look at SetPrecision[] and Precision[] and related functions. Also, look at this tutorial and scroll to Arbitrary Precision numbers.
However, I find strange that Mathematica is not able to compute properly a simple division like 24.9 / 6 without using the Rationalize function. My calculator do it without any probleme…
However, I find strange that Mathematica is not able to compute properly a simple division like 24.9 / 6 without using the Rationalize function. My calculator do it without any probleme…
Mathematica does do 24.9/ 6 exactly like your calculator. It even displays 4.15 . The calculator rounds to 10 or 12 or some number of digits that is has in its display. If you round to 12 digits in Mathematica you also get 4.15 exactly. The problem is you are rounding to a very low precision and bypassing that internal round that the calculator does to display the result. Using a version of Hans’ suggestion would be more like the calculator and could fix any floating point errors. First a round to 14 or 15 decimal places and then round to what you want at lower precision would mimic the calculator’s internal operation.
This is a classical problem in computing with floating point numbers. If you use C or any other language you would get the exact same result. Besides, as a theoretical issue, you should NEVER round to a digit that you care about (where ±1 makes a difference). If a difference in (for example) the 3rd decimal place matters to you, you should round below that (say the 4th decimal place) or you will get exactly the “error” that you are seeing.
Further to your answers, I 've yeasterday done some manipulations with Mathematica and I’ve realized something very strange (for me):
When you eval Round[21.5], Mathematica returns 22 what you are waiting for. But when you eval Round[22.5], Mathematica returns 22 too. For an average user, this incoherence is not obvious to understand.
Obviously, my interest was to understand why Round[5.25,0.1] gives 5.2 and Round[5.15,0.1] too. Indeed, this type of rounding often occurs in my job (teacher of mathematics) when I calculate some mean of notes rounded to the tenth.
Have you an explanation for this apparent incoherence ?