Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.1 - 日本語

Change language to:
English - Français - Português - Русский

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

Scilabヘルプ >> Output functions > printf_conversion

printf_conversion

mprintf, msprintf, mfprintf 変換仕様

説明

mprintf , msprintf , mfprintfにおける各変換仕様. format パラメータは以下のような構文を有します:

  • A % (パーセント) 符号.

  • An optional integer n ≥ 1 followed by "$". n is the index of the input data to substitute to the placeholder, in the msprintf, mprintf .. list of input data. In a format string, placeholders are either all numbered or all non-numbered. A given numbered placeholder can be used only once in its C-format string (Scilab limitation).

  • 0個以上の optionsで, 変換仕様の意味を修正します. 以下のリストにoption文字とその意味を示します:

    - : 左揃え, フィールド内では, 変換の結果.
    + : (+または -)を指定する符号変換の結果を開始.
    ' ' : (空白) 符号変換後の最初の文字が符号ではない場合に結果の 前に空白文字を付加します. (空白) および +オプションが共に指定された場合, (空白) オプションは無視されます.
    # : 別の形式に値を変換. c, d, i, s, および u 変換の場合, #オプションの効果はありません. o 変換の場合, # は 結果の最初の桁を強制的に0 (ゼロ)にし,精度を増加させます. x および X変換の場合, ゼロでない結果の前に0xまたは0Xが付加されます. e, E, f, g, および G変換の場合, 小数点以下の値がない場合でも結果には常に小数点が含まれます. g および G 変換の場合, 末尾の0は結果から除かれません.
    0 : d, i, o, u, x, X, e, E, f, g, および G変換において (符号または基底の指示子の後に) 前に0をつけることによりフィールド幅内を埋めます: 空白によるパディングは行われません 0 および \-(ダッシュ)が共に指定された場合, 0フラグは無視されます. d, i, o u, x, および X 変換の場合, 精度が指定されると, 0 フラグも無視されます.

オプションの10進数文字列は 最小フィールド幅を指定します. 変換された値の文字がこのフィールド幅よりも少ない場合, フィールドはフィールド幅の指定長まで左側にパディングされます. 左寄せオプションが指定された場合, フィールドは右側にパディングされます.

オプションの精度. 精度は . (ドット)の後に 10進数文字列が続きます. 精度が指定されない場合, このパラメータは 0 (ゼロ)と扱われます. 精度指定子:

  • d, u, o, x, または X変換に関する最小表示桁数
  • e, E, および f における小数点の後に表示する桁数
  • g およびG変換における 有効桁の最大値
  • s変換において文字列から出力される 最大文字数
  • 適用される変換の種類を示す文字:
    % : 変換しません. %を表示.
    This may be useful for instance to print percentages, or to process some LaTeX expression including LaTeX comments starting with "%", etc.
    s : Accepts a string or boolean value, 文字列から末尾または精度に示された文字数に達するまで, 文字に変換します.精度が指定されない場合,末尾までの全ての文字が 表示されます. Input strings including some UTF-8 extended characters are supported. Booleans are converted into 'T' or 'F'.
    c : Not supported.
    All following conversions accept any decimal numerical or boolean input value. Only the real part of any input complex number is considered. Booleans are implicitly converted into 0 and 1.
    d, i : Converts the input value to a signed integer int32 notation. Conversions for input |Numbers| ≥ 2^31 are not reliable. 精度は表示される最小の桁数を指定します. 変換される値がより少ない桁数で表せる場合, 前にゼロを付加して拡張されます. デフォルトの精度は1です.値0を精度0で変換した結果は, ヌル文字列となります. 前に付加する文字をゼロとしてフィールド幅を指定すると, フィールド幅までの値では前にゼロを付加するパディングが 行われます.
    u : Converts the input value to an unsigned integer uint32 notation. Conversions for input |Numbers| ≥ 2^32 are not reliable. 精度は表示される最小の桁数を指定します. 変換される値がより少ない桁数で表せる場合, 前にゼロを付加して拡張されます. デフォルトの精度は1です.値0を精度0で変換した結果は, ヌル文字列となります. 前に付加する文字をゼロとしてフィールド幅を指定すると, フィールド幅までの値では前にゼロを付加するパディングが 行われます.
    o : Converts the input value to an unsigned octal notation. Conversions for input |Numbers| ≥ 2^32 are not reliable. 精度は表示される最小の桁数を指定します. 変換される値がより少ない桁数で表せる場合, 前にゼロを付加して拡張されます. デフォルトの精度は1です.値0を精度0で変換した結果は, ヌル文字列となります. 前に付加する文字をゼロとしてフィールド幅を指定すると, フィールド幅までの値では前にゼロを付加するパディングが 行われます. フィールド幅に8進数を使用することはできません.
    x, X : Converts the input value to an unsigned hexadecimal notation. Conversions for input |Numbers| ≥ 2^32 are not reliable. x変換では, 文字``abcdef''が使用されます;X変換では, 文字``ABCDEF''が使用されます. 精度はは表示される最小の桁数を指定します. 変換される値がより少ない桁数で表せる場合, 前にゼロを付加して拡張されます. デフォルトの精度は1です.値0を精度0で変換した結果は, ヌル文字列となります. 前に付加する文字をゼロとしてフィールド幅を指定すると, フィールド幅までの値では前にゼロを付加するパディングが 行われます.
    f : Converts the input value to a decimal notation in the format %[\-]ddd.ddd. 小数点以下の桁数は,精度指定子に等しくなります.
    • 精度が指定されない場合, 6桁が出力されます.
    • 精度がゼロの場合, 小数点は表示されず, システムはvalueに最も近い整数に丸めた数を 出力します.
    • 小数点が出力される場合,最低でも1桁がその前に出力されます.
    e, E : Converts the input value to the exponential form %[\-]d.ddde+/\-dd. 小数点の前に1桁があり,小数点の後の桁数は精度指定子に等しくなります.
    • 精度が指定されない場合, 6桁が出力されます.
    • 精度がゼロの場合, 小数点は表示されません.
    • E 変換文字の場合, 指数の前の e の代わりに E を付けた数値を出力します. 指数には常に2桁以上が含まれます. 値が 0 の場合, 指数は 0 となります.
    g, G : 有効桁数を指定する精度を付けた e, E, または f変換文字の形式に変換します. Booleans are converted into 0 and 1. Only the real part of complex numbers is considered. 末尾のゼロは結果から削除されます. 小数点は数字が続く場合にのみ表示されます. 使用される形式は変換される値に依存します. 変換結果の指数が-4よりも小さい場合,または, 精度より大きいか等しい場合に, e (使用されるフラグがGの場合は E)形式が使用されます.

フィールド幅または精度は, 桁文字の代わりに* (アスタリスク)で 示すことができます. この場合,整数 valueパラメータは フィールド幅または精度を指定します. 出力に変換されるvalue パラメータは 変換文字が達するまで取得されません. このため, フィールド幅または精度を指定するパラメータは変換される値よりも 前に現れる必要があります.

変換の結果がフィールド幅よりも広い場合, このフィールドは変換結果を含められる幅まで拡張されます.

+記号の意味は+または(空白)整形オプションの どちらが指定されたかに依存します.

指数形式 %e の表示はプレットフォームに依存し, 指数の桁数は異なります.

プラットフォーム 例: msprintf("%e",1.23e4)
Windows 1.23000e+004
Linux/Mac OS 1.23000e+04

Special escaped sequenced are supported in 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 \

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 αβδ εϵ  ζηθικλ

参照

  • mprintf — 変換, 整形し, Scilab主ウインドウにデータを書き込む
  • mfprintf — converts, formats, and writes data to a file
  • msprintf — converts, formats, and writes data in a string

履歴

バージョン記述
6.1.0 Numbered placeholders "%n$.." are supported.
6.1.1 Input boolean data can be converted.
Report an issue
<< print Output functions Xcos >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Jan 03 14:37:53 CET 2022