Printf, sprintf, fprintf conversion specifications (original) (raw)

Please note that the recommended version of Scilab is 2026.0.1. This page might be outdated.
See the recommended documentation of this function

Scilab help >> 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:

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