Filter löschen
Filter löschen

sprintf for 3.1901 to show 03.190

1 Ansicht (letzte 30 Tage)
Purnendu Nath
Purnendu Nath am 15 Apr. 2020
Kommentiert: Purnendu Nath am 15 Apr. 2020
I have the numbers
s = 3.1901
and
ss = 13.1905
and want to use
sprintf(formatSpec, s) and sprintf(formatSpec, ss)
to return
03.190 {i.e. rounded to 3DP and the leading zero shown}
and
13.191 {i.e. rounded to 3DP}
so both 3.1901 and 13.1905 should return
2 places before the DP (leading zero for 3.1901)
and
3 places after the DP (rounded to 3 DP)
I am struggling to figure out the correct formatSpec when calling sprintf(formatSpec, ....)

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 15 Apr. 2020
%06.3f should do it.
  1 Kommentar
Purnendu Nath
Purnendu Nath am 15 Apr. 2020
Thanks Walter!
I figured it out after struggling for an hour and then looking on Stack overflow in general printf rather than Matlab specific pages... Your confirmation is of value too, I appreciate it.
Cheers!
Purnendu

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by