Programming  Display Format for Numeric Values

By default, MATLAB displays numeric output as 5-digit scaled, fixed-point values. You can change the way numeric values are displayed to any of the following:

• 5-digit scaled fixed point, floating point, or the best of the two
• 15-digit scaled fixed point, floating point, or the best of the two
• A ratio of small integers
• Hexadecimal (base 16)
• Bank notation

All available formats are listed on the `format` reference page.

To change the numeric display setting, use either the `format` function or the Preferences dialog box (accessible from the MATLAB File menu). The `format` function changes the display of numeric values for the duration of a single MATLAB session, while your Preferences settings remain active from one session to the next. These settings affect only how numbers are displayed, not how MATLAB computes or saves them.

Display Format Examples

Here are a few examples of the various formats and the output produced from the following two-element vector `x`, with components of different magnitudes.

Check the current format setting:

• ```get(0, 'format')
ans =
short
```

Set the value for `x` and display in 5-digit scaled fixed point:

• ```x = [4/3 1.2345e-6]
x =
1.3333    0.0000
```

Set the format to 5-digit floating point:

• ```format short e
x
x =
1.3333e+000  1.2345e-006
```

Set the format to 15-digit scaled fixed point:

• ```format long
x
x =
1.33333333333333   0.00000123450000
```

Set the format to `'rational'` for small integer ratio output:

• ```format rational
x
x =
4/3          1/810045
```

Set an integer value for `x` and display it in hexadecimal (base 16) format:

• ```format hex
x = uint32(876543210)
x =
343efcea
```

Setting Numeric Format in a Program

To temporarily change the numeric format inside a program, get the original format using the `get` function and save it in a variable. When you finish working with the new format, you can restore the original format setting using the `set` function as shown here:

• ```origFormat = get(0, 'format');
format('rational');

-- Work in rational format --

set(0,'format', origFormat);
``` Identifying Numeric Types Function Summary © 1994-2005 The MathWorks, Inc.