format
set the default output format of decimal numbers
Syntax
format(mode) format(width) format(mode, width) format(wm) mw = format()
Arguments
- mode
formatting mode:
1 or "v": variable adaptative formatting. Scilab chooses either the direct representation (e.g. -143.8757) or the exponential/scientific notation (e.g. -1.438E+02), in order to cope with each processed value as well as with the required width, with a maximal number of output digits.
0 or "e": The exponential /scientific notation is forced and used for all numbers.
2 or "eng": The engineering notation is used. This notation is similar to the exponential/scientific notation but the exponent value is selected to be divisible by three.
- width
width of numbers = number of output characters used, all included: sign of the mantissa, its digits, decimal separator, exponent symbol, sign and digits of the exponent. Default width = 10. Minimal width in "e" mode = 8.
- wm
a vector to set new format
wm(1)is the widthwm(2)is the formatting mode: 0 for'e', 1 for'v'and 2 for'eng'- mw
vector returning the current formatting parameters:
mw(1)is the formatting mode: 0 for'e', 1 for'v'and 2 for'eng'mw(1)is the formatting mode: 0 for'e'and 1 for'v'mw(2)is the width: Number of characters used to output each number.
Description
![]() | For complex numbers, each real and imaginary decimal part is
output according to |
![]() | Encoded integers are never output according to the "e"xponential mode, even when this formatting is the default mode set for decimal numbers. For them, the decimal separator "." is skipped. This allows to distinguish them from decimal integers that have a dot. |
![]() | For wide format(), digits that may be displayed beyond the
relative accuracy |
![]() | The default decimal format set with
|
In the old Scilab versions, in "variable format" mode, vector
entries which are less than %eps times the maximum absolute value of the
entries were displayed as "0". It is no more the case, the clean function
can be used to set negligible entries to zeros.
Examples
// format() is not taken into account for encoded integers // ------------------------------------------------------- format("e",8) int32(2.^grand(3,5,"uin",0,30)) // format() impacts console's output, disp(), string(), sci2exp(),... // -------------------------------------------------------------- a = %pi; p = %pi + %z - %e*%z^2; format("v",10); a, p disp(a,p) string(a), string(p) [sci2exp(a) sci2exp(p)] format("e",15); a, p disp(a,p) string(a), string(p) [sci2exp(a) sci2exp(p)] format("v",10); // reset // with engineering notation the exponent of ten is divisible by 3 x = %pi*10^(-5:5)' format("e") xs = string(x); format("eng") xs = [xs string(x)]; table(xs,"VariableNames",["format(""e"")" "format(""eng"")"]) // format() set the width, not a fixed number of digits: // ---------------------------------------------------- format("v",10) %pi*1e-217, s = string(%pi*1e-217) length(s) // the missing char is the implicit "+" sign // This is useful to get aligned and fully informative display of matrices [ -1.234 %pi*1e-10 %nan ; %e*1e137 -%inf 54312] // Since Scilab 6.0, unrelevant digits displayed with wide format() are set to 0: format(22) %pi // format() has a global impact // ---------------------------- function myfun() format("e",20) endfunction format("v", 10) disp(%pi) myfun() // it remains everywhere, wherever it has been set: disp(%pi) format("v",10) // reset
See also
- numbers properties — determine floating-point parameters
- string — conversion to character string
- sci2exp — returns a string able to generate a given Scilab object
- disp — displays variables
- print — prints variables in a file
- clean — cleans matrices (round to zero small entries)
- C-like format — mprintf, msprintf, mfprintf C-format specifications
- mprintf — converts, formats, and writes data to the main scilab window
- msprintf — converts, formats, and writes data in a string
- mfprintf — converts, formats, and writes data to a file
History
| Version | Description |
| 6.0 | For wide format(), digits that may be displayed beyond the relative accuracy %eps are now set to 0. |
| 2026.1 | Engineering notation added. |
| Report an issue | ||
| << floor | Floating point | ieee >> |

