Number of leading zeroes as a variable
12 views (last 30 days)
I know that to print out a number with a certain amount of leading zeroes, you are supposed to use %0X, where X is the number of digits you want in your output. For example, sprintf('%06g',13) gives you the string '000013' as output. Is there a way to make the formatting value a variable? Something along the lines of
I know it can be done with a for loop, but is there are way to implement this directly into the sprintf command?
dpb on 24 Oct 2016
Fer shure, just write the format string desired dynamically--
Nz for "Number zeros" seemed a better variable name than y as did an s for a returned string output variable...the format string expression can be wrapped inside the sprintf call, of course, just wrote it out for clarity here.