Qu

sprintf

Builtin index · Collections & strings

result = sprintf(fmt, ...)

Input: fmt, ... · Output: result

What it is

C/MATLAB-style formatting: fmt is a Str with conversions %d %i %u (integers), %f %e %E %g %G (reals), %s (any value as text), %c, %x %X %o and %%, each with optional flags (- left-align, + sign, space, 0 zero-pad, # prefix), a width and a .precision (%08.3f, %-10s, %+.2e). One argument per conversion, in order; too few is an error that says so. A vector, list or matrix argument contributes its elements, and when arguments are left over the format is applied again from the start (MATLAB's rule): sprintf("%d,", [1, 2, 3]) is "1,2,3,". A * takes the width or precision from an argument (%*d, %.*f), and C length modifiers (%ld, %lu, %lf, %hd) are accepted and ignored. %e writes 1.235e+04 (signed exponent, at least two digits) and %g follows C's significant-digit rules. A non-integer under %d prints in its shortest general form instead of being truncated.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = sprintf(fmt, ...)
fmt StrC/MATLAB-style formatting: fmt is a Str with conversions %d %i %u (integers), %f %e %E %g %G (reals), %s (any value as text), %c, %x %X %o and %%, each with optional flags (- left-align, + sign, space, 0 zero-pad, # prefix), a width and a .precision (%08.3f, %-10s, %+.2e).
... repeatablenot documented yet
result Str
Returns the Str.

Examples

No documentation example calls this form yet. The Collections & strings chapter is where one belongs.