Displaying a value using fprintf with certain number of decimals.
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to display the value of a using fprintf with only two decimals. Given a = 3.870081e+01;
Can you modify my code below to only display two decimals?
fprintf('The answer for a is %d m/s\n', a)
Thanks,
댓글 수: 0
채택된 답변
Walter Roberson
2021년 3월 5일
format long g
a = rand*10
fprintf('The answer for a is %.2f m/s\n', a)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!