Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: English - Français - Português - Русский

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

Scilabヘルプ >> Elementary Functions > Floating point > format

format

set the default output format of decimal numbers

Syntax

format(mode)
format(width)
format(mode, width)
format(wm)
v = format()

Arguments

mode

formatting mode:

  • 1 or "v": variable adaptative formatting. Scilab chooses either the direct representation (e.g. -143.8757) or the exponential/engineering/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 /engineering notation is forced and used for all numbers.

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 width

wm(2) is the formatting mode: 0 for 'e' and 1 for 'v'

v

vector returning the current formatting parameters:

  • v(1) is the formatting mode: 0 for 'e' and 1 for 'v'
  • v(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 format(..). The total width of a complex number is therefore roughly twice greater (+ 1 character for "i" symbol).
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 %eps are set to 0.
The default decimal format set with format(..) is a global parameter: Wherever you set it, it then applies everywhere in Scilab and Xcos.

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

// 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 — 浮動小数点数パラメータを定義する
  • string — 文字列に変換
  • sci2exp — 式を文字列に変換
  • disp — 変数を表示
  • print — 変数をファイルに出力する
  • clean — 行列を消去 (小さなエントリをゼロに丸める)
  • C-like format — mprintf, msprintf, mfprintf 変換仕様
  • mprintf — 変換, 整形し, Scilab主ウインドウにデータを書き込む
  • msprintf — データを変換,整形し,文字列に書き込む
  • mfprintf — 変換,整形し,ファイルにデータを書き込む

History

バージョン記述
6.0 For wide format(), digits that may be displayed beyond the relative accuracy %eps are now set to 0.
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 14 15:10:27 CET 2017