How to Format Decimal Places in MATLAB

Written by michael peter
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Format Decimal Places in MATLAB
The number of digits displayed after the decimal place can be changed in MATLAB. ( Images)

The technical computing software MATLAB is used by scientists and engineers for data processing and analysis. Frequently, data contained in arrays and matrices are manipulated using built-in array and matrix functions until the data is represented in the correct form. During algorithm development, calculations are often performed step-by-step in the Command window to see the resulting answer. The standard MATLAB display format rounds the displayed number to four places. Numbers that are longer retain their numerical values to 15 places during the calculation but are still only displayed to four places. It frequently becomes necessary to display all 15 places during the arithmetic depending on the precision of the calculation.

Skill level:
Moderately Easy

Other People Are Reading


  1. 1

    Clear all active variables in the workspace by entering "Clear all" into the MATLAB "Command" window.

  2. 2

    Create a number that has an unlimited amount of digits to the right of the decimal place. The fraction "1/3" has the number "3" repeated after the decimal to infinity, so input "1/3" into the "Command" window. MATLAB outputs "0.3333" with four digits shown to the right of the decimal.

  3. 3

    Increase the amount of digits displayed. Enter "format long" into the Command window. Repeat Step 2 and input "1/3" into the "Command" window. MATLAB now outputs "0.333333333333333," which displays fifteen digits to the right of the decimal.

  4. 4

    Decrease the amount of digits displayed by entering "format short." Repeating Step 2 outputs "0.3333," the same results as in the second step.

Tips and warnings

  • Although MATLAB displays only four digits to the right of the decimal in "format short," MATLAB uses the 15-digit number to perform the calculation. Verify this by first inputting "format short" into the Command window followed by the command "pi." MATLAB outputs "3.1416." Click on the "ans" variable in the Workspace window. The Variable Editor opens with "pi" represented using 15 digits after the decimal.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.