printf Output functions sprintf

Scilab manual >> Output functions > printf_conversion

printf_conversion

printf, sprintf, fprintf conversion specifications

Description

Each conversion specification in the printf , sprintf , fprintf format parameter has the following syntax:

An optional decimal digit string that specifies the minimum field width. If the converted value has fewer characters than the field width, the field is padded on the left to the length specified by the field width. If the left-adjustment option is specified, the field is padded on the right.

An optional precision. The precision is a . (dot) followed by a decimal digit string. If no precision is given, the parameter is treated as 0 (zero). The precision specifies:

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.

display of exponential form %e is platform dependant with a different number of digits in exponent.

Platform Example: sprintf("%e",1.23e4)
Windows 1.23000e+004
Linux/Mac OS 1.23000e+04

Examples

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

See Also

printf Output functions sprintf