MATLAB: Why am I getting .99999999999

format longnumber representation

I'm wondering why numbers are being represented with unusual representations. For example in format long
>> 8.2
ans =
8.199999999999999
Similarly, >> 13.46
ans =
13.460000000000001
But not all numbers do this.
>> 6.3
ans =
6.300000000000000

Best Answer

It is ‘floating-point approximation error’. It is similar to the problem of representing the fraction ‘1/3’ in decimal notation: 0.3333....
For a much more extensive discussion, see: Why is 0.3 - 0.2 - 0.1 (or similar) not equal to zero? (link)