MATLAB Answers

Show limited digits numbers.

2 views (last 30 days)
armin m
armin m on 15 Oct 2021
Commented: armin m on 16 Oct 2021
Hi i wanna numbers limited to 6 digits. For example. A=2.54357766 be show A=2.543578. Tnx
  2 Comments
armin m
armin m on 16 Oct 2021
Command windows and every where i wanna to print. E.g .txt file from diary on mode. But my main purpose relate to calculation. I have ref. Which calculated accordding to 6 digits numbers so i think the numbers with for example 10 digits have effect on result. So i wanna decrease digits to 6 to compare my results with reference.

Sign in to comment.

Answers (1)

Chunru
Chunru on 16 Oct 2021
You can use fprintf with format specifier to format the print out. "doc fprintf".
A=2.54357766;
fprintf('%.6f\n', A);
2.543578
  2 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by