Display double number with 6 digits exactly

조회 수: 5 (최근 30일)
Askic V
Askic V 2022년 10월 17일
댓글: Askic V 2022년 10월 21일
Hello,
I would like to create a string that will contain a double number. This number should be represented with 6 digits exactly.
For example:
x = 12.45;
str_x = sprintf('The number is %f\n', x);
should output 12.4500

채택된 답변

Stephen23
Stephen23 2022년 10월 19일
sprintf('The number is %#.6g', 12.45)
ans = 'The number is 12.4500'
sprintf('The number is %#.6g', 2)
ans = 'The number is 2.00000'

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by