strfmonのヘルプ・マニュアル
日本語 英語
strfmon --help
man strfmon
STRFMON(3) Linux Programmer’s Manual STRFMON(3)
名前
strfmon - 金額の値を文字列に変換する
書式
#include
ssize_t strfmon(char *s, size_t max, const char *format, ...);
説明
strfmon() 関数は、指定された数量を format で指定されたフォーマットにし
たがって整形し、結果をサイズ max の文字配列 s に書きこむ。
format 中の通常の文字は、変換されずにそのまま s にコピーされる。変換 指
定 は '%' 文字で始まる。この直後には、以下のフラグを 0 個以上続けること
ができる。
=f 1 バイト文字 f を数値埋め文字 (numeric fill character) にする (
左 精度と共に用いる。以下を参照)。指定されないと、スペース文字が
用いられる。
^ 現在のロケールで定義されているであろうグループ化文 字 (grouping
character) を一切使わない。デフォルトではグループ化は有効になっ
ている。
( または +
( フラグは、負の数値を括弧で括ることを意味する。 + フラグは符 号
をデフォルトのように取り扱うことを意味する (すなわち数値の前にロ
ケールの符号マークが置かれる。例えば正ならなにもなく、負なら '-'
を置く、など)。
! 通貨シンボルを省略する。
- すべてのフィールドを左詰めにする。デフォルトは右詰め。
次 の位置には、フィールドの幅を指定できる。 10 進の数値文字列で、フィー
ルドの最小幅をバイト単位で指定する。デフォルトは 0。結果がこの幅より も
狭 くなった場合には、不足分がスペースで埋められる (左詰めフラグが指定さ
れていなければ左側が埋められる)。
次の位置には、"#" に 10 進数値文字列を続けた形式で、左精度 (left preci-
sion) を指定できる。通貨の基数点 (radix) より左側の数値の桁数がこの指定
より小さい場合は、数値埋め文字で左側が埋められる。このフィールド幅の 指
定では、グループ化文字はカウントされない。
次 の位置には、"." に 10 進数値文字列を続けた形式で、右精度 (right pre-
cision) を指定できる。整形される数値は、整形前にこの桁数に丸められる 。
デ フォルトではカレントロケールの frac_digits と int_frac_digits の指定
を用いる。右精度が 0 の場合は、基数点文字 (radix character) は印字さ れ
ない (ここでの基数点文字は LC_MONETARY で定義されており、 LC_NUMERIC の
指定とは異なっていてもよい)。
最後に、変換指定は変換文字 (conversion character) で終了しなければな ら
ない。変換文字には以下の 3 つがある。
% ( この場合は指定全体が "%%" でなければならない。) 結果の文字列に
'%' 文字を書きこむ。
i double 型の引き数ひとつが、ロケールの国際通 貨 フ ォ ー マ ッ ト
(international currency format) を用いて変換される。
n double 型 の 引 き 数 ひとつが、ロケールの国内通貨フォーマット
(national currency format) を用いて変換される。
返り値
strfmon() 関数は、結果の文字列が終端の NULL バイトを含めて配列 s に収ま
っ た場合には、 s に書きこまれた文字数を返す。NULL バイトは文字数に入ら
ない。それ以外の場合には、 errno に E2BIG を設定して -1 を返す。この 場
合の配列の内容は未定義である。
準拠
POSIX.1-2001 にはない。他のいくつかのシステムに存在する。
例
strfmon(buf, sizeof(buf), "[%^=*#6n] [%=*#6i]",
1234.567, 1234.567);
の ような関数コールの出力は、オランダのロケールでは以下のような出力にな
る。
[ fl **1234,57] [ NLG **1 234,57]
(fl は "florijnen" の意。NLG は Netherlands Guilder。) グループ化文字を
用 いると非常に醜くなる。同時に間違いなく混乱の原因にもなってしまうだろ
う。これは数値の半分以下の幅であるべきだが、数値と同じだけの幅を取っ て
し まうからである。ひどいことに、 "fl" の前後にはスペースが入ってしまい
、また "NLG" の前には 1 つ、後には 2 つのスペースが置かれている。これは
ロ ケールファイルのバグであろう。イタリア・オーストラリア・スイス・ポル
トガルの各ロケールでの結果は以下のようになる。
[ L. **1235] [ ITL **1.235]
[ $**1234.57] [ AUD **1,234.57]
[Fr. **1234,57] [CHF **1.234,57]
[ **1234$57Esc] [ **1.234$57PTE ]
関連項目
setlocale(3), sprintf(3), locale(7)
Linux 2000-12-05 STRFMON(3)
STRFMON(3) Linux Programmer’s Manual STRFMON(3)
NAME
strfmon - convert monetary value to a string
SYNOPSIS
#include
ssize_t strfmon(char *s, size_t max, const char *format, ...);
DESCRIPTION
The strfmon() function formats the specified amounts according to the
format specification format and places the result in the character
array s of size max.
Ordinary characters in format are copied to s without conversion. Con-
version specifiers are introduced by a '%' character. Immediately fol-
lowing it there can be zero or more of the following flags:
=f The single-byte character f is used as the numeric fill charac-
ter (to be used with a left precision, see below). When not
specified, the space character is used.
^ Do not use any grouping characters that might be defined for the
current locale. By default, grouping is enabled.
( or + The ( flag indicates that negative amounts should be enclosed
between parentheses. The + flag indicates that signs should be
handled in the default way, that is, amounts are preceded by the
locale’s sign indication, for example, nothing for positive, "-"
for negative.
! Omit the currency symbol.
- Left justify all fields. The default is right justification.
Next, there may be a field width: a decimal digit string specifying a
minimum field width in bytes. The default is 0. A result smaller than
this width is padded with spaces (on the left, unless the left-justify
flag was given).
Next, there may be a left precision of the form "#" followed by a deci-
mal digit string. If the number of digits left of the radix character
is smaller than this, the representation is padded on the left with the
numeric fill character. Grouping characters are not counted in this
field width.
Next, there may be a right precision of the form "." followed by a dec-
imal digit string. The amount being formatted is rounded to the speci-
fied number of digits prior to formatting. The default is specified in
the frac_digits and int_frac_digits items of the current locale. If
the right precision is 0, no radix character is printed. (The radix
character here is determined by LC_MONETARY, and may differ from that
specified by LC_NUMERIC.)
Finally, the conversion specification must be ended with a conversion
character. The three conversion characters are
% (In this case the entire specification must be exactly "%%".)
Put a '%' character in the result string.
i One argument of type double is converted using the locale’s
international currency format.
n One argument of type double is converted using the locale’s
national currency format.
RETURN VALUE
The strfmon() function returns the number of characters placed in the
array s, not including the terminating null byte, provided the string,
including the terminating null byte, fits. Otherwise, it sets errno to
E2BIG, returns -1, and the contents of the array is undefined.
CONFORMING TO
Not in POSIX.1-2001. Present on several other systems.
EXAMPLE
The call
strfmon(buf, sizeof(buf), "[%^=*#6n] [%=*#6i]",
1234.567, 1234.567);
outputs
[ fl **1234,57] [ NLG **1 234,57]
in the Dutch locale (with fl for "florijnen" and NLG for Netherlands
Guilders). The grouping character is very ugly because it takes as
much space as a digit, while it should not take more than half that,
and will no doubt cause confusion. Surprisingly, the "fl" is preceded
and followed by a space, and "NLG" is preceded by one and followed by
two spaces. This may be a bug in the locale files. The Italian, Aus-
tralian, Swiss and Portuguese locales yield
[ L. **1235] [ ITL **1.235]
[ $**1234.57] [ AUD **1,234.57]
[Fr. **1234,57] [CHF **1.234,57]
[ **1234$57Esc] [ **1.234$57PTE ]
SEE ALSO
setlocale(3), sprintf(3), locale(7)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2000-12-05 STRFMON(3)