How to display 3 decimal places using the g format?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponses (1)
Walter Roberson
le 7 Oct 2018
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.
0 commentaires
Voir également
Catégories
En savoir plus sur Elementary Math dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!