MATLAB: Will round() not work on this number for 4 decimal places

bug

Found an unepected behavior for round(x,4) where x = -9.039999999999999.
>> round(-9.039999999999999,4)
ans =
-9.039999999999999
I tried round() on similar number numbers (ex: round(-3.03999999999,4)).
In other cases round() behaved as expected.
Can anyone explain what's going on here?

Best Answer

"Why will round() not work on this number for 4 decimal places?"
It does work. It rounds to the nearest floating point number.
"Found an unepected behavior for round..."
Rounding to the nearest floating point number is the expected behavior (and is really the only possible behavior if working only with double numbers).
"Can anyone explain what's going on here?"
The value that you are trying to round to cannot be exactly represented using binary floating point numbers. What you see printed in the command window is the closest representation to 16 significant digits. KALYAN ACHARJYA's answer shows the closest representation to 5 significant digits. Neither of these representations is more correct than the other, they are just the same floating point number displayed to different precisions. Neither of them is the "real" value. To see the "real" value download James Tursa's FEX submission:
"In other cases round() behaved as expected."
Use James Tursa's num2strexact and you will see that none of your "expected" values really have the values that you think they do (unless they are powers of two). All you are looking at is a representation of those floating point numbers displayed in the command window, to the precision defined by your format setting. Just because you see 0.1000 displayed tells you nothing about the "real" floating point number's value.
Note that you can change how the value is displayed by changing the format. This is the only difference between KALYAN ACHARJYA's answer and your question.
You need to learn about the limits of floating point numbers. Start by reading these:
This is worth reading as well: