<< print Output functions Xcos >>

Scilab Help >> Output functions > printf_conversion

printf_conversion

mprintf, msprintf, mfprintf C-format specifications

Description

Each conversion specification in the mprintf , msprintf , mfprintf format string has the following syntax:

A field width or precision can be indicated by an * (asterisk) instead of a digit string. In this case, an integer value parameter supplies the field width or precision. The value parameter converted for output is not fetched until the conversion letter is reached, so the parameters specifying field width or precision must appear before the value to be converted (if any).

If the result of a conversion is wider than the field width, the field is expanded to contain the converted result.

The representation of the plus sign depends on whether the + or (space) formatting option is specified.

The display of exponential form %e is platform dependent with a different number of digits in exponent.
Platform Example: msprintf("%e",1.23e4)
Windows 1.23000e+004
Linux/Mac OS 1.23000e+04

Special escaped sequences are supported in Scilab C-format strings:
\n : Go to Next line (line feed)
\r : Return: go to the head of current line (for overprinting)
\t : horizontal Tab
\\ : print a backslash \

Examples

mprintf('a string: %s\n', 'Scilab');
mprintf('an integer: %d\n', 10);
mprintf('an integer: %4d\n', 10);
mprintf('a left justified integer: %-4d\n', 10);
mprintf('an integer converted to float: %#fd\n',10);
mprintf('an integer with a sign: %+4d\n', 10);
mprintf('an integer with a sign: %+4d\n', -10);
mprintf('an integer padded with zeros: %04d\n', 10);
mprintf('an unsigned integer: %u\n', 10);
mprintf('an unsigned integer: %4u\n', -10);
mprintf('an integer converted to hexadecimal: %x\n', 10);
mprintf('a float: %d\n', %pi);
mprintf('a float: %3.2d\n', %pi);
mprintf('a float (exponential form): %3.2e\n', %pi);
mprintf('a float (exponential form): %3.2g\n', %pi);
mprintf('a character: %c\n', 'a');
mprintf('a character: %c\n', 'aaa');

With input booleans:

mprintf("\n%%d: %d,  %%u: %u,  %%o: %o,  %%f: %f,  %%e: %e,  %%s: %s\n" + ..
          "%%d: %d,  %%u: %u,  %%o: %o,  %%f: %f,  %%e: %e,  %%s: %s\n", ..
        %T, %T, %T, %T, %T, %T, %F, %F, %F, %F, %F, %F);
%d: 1,  %u: 1,  %o: 1,  %f: 1.000000,  %e: 1.000000e+00,  %s: T
%d: 0,  %u: 0,  %o: 0,  %f: 0.000000,  %e: 0.000000e+00,  %s: F

With numbered placeholders:

mprintf("%2$s is %1$d-year old.\n", 32, "Peter");
Peter is 32-year old.

With escaped sequences and UTF-8 extended characters:

mprintf("The path T:\\abc does not exist.\n");
mprintf("abcdefghijk\tαβδ\tεϵ\tζηθικλ\rABCDE\n");
--> mprintf("The path T:\\abc does not exist.\n");
The path T:\abc does not exist

--> mprintf("abcdefghijk\tαβδ\tεϵ\tζηθικλ\rABCDE\n");
ABCDEfghijk αβδ εϵ  ζηθικλ

See also

History

VersionDescription
6.1.0 Numbered placeholders "%n$.." are supported.
6.1.1 Input boolean data can be converted.

Report an issue
<< print Output functions Xcos >>