Number Formatting

Matlab will often display numbers with a given number of decimals based on "formatting" options as opposed to their actual value.

Formatting Numbers

Note: While I will differentiate between integers and doubles, Matlab will treat most numbers (unless it is explicitly told otherwise) as doubles.

This is because, from a scientific viewpoint, doubles are the most accurate representation the computer can (typically) use. We will talk about the limits of precision on a computer at another time.

Matlab usually only prints a very small number of the digits after the decimal place... This is because to us,


is the same as:


You can change this behavior by using the "format" command

>> format long
>> a

a =


>> format short
>> a

a =


Back to Topics List