How to display 3 decimal places using the g format?

조회 수: 5 (최근 30일)
Peculiar Lawrence
Peculiar Lawrence 2018년 10월 7일
답변: Walter Roberson 2018년 10월 7일
Please how do I display a number rounded to 3 decimal places (XXX.XXX) using fprintf and the g format. This is what I have now:fprintf('The roots of the cubical equation are %7.3g,%7.3g,%7.3g.\n',x1,x2,x3) but it rounds it to 2 decimal places.

답변 (1개)

Walter Roberson
Walter Roberson 2018년 10월 7일
You would use %f format. g format deals with total significant figures including before the decimal place so if you want a particular number of digits after the decimal place then it is the wrong format.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by