Displaying a value using fprintf with certain number of decimals.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Shinichiro Shimata
am 5 Mär. 2021
Beantwortet: Walter Roberson
am 5 Mär. 2021
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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 5 Mär. 2021
format long g
a = rand*10
fprintf('The answer for a is %.2f m/s\n', a)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!