strfmon

Section: C Library Functions (3)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

strfmon, strfmon_l - convert monetary value to a string  

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#include <monetary.h>

ssize_t strfmon(size_t size;
                char s[restrict size], size_t size,
                const char *restrict format, ...);
ssize_t strfmon_l(size_t size;
                char s[restrict size], size_t size, locale_t l,
                const char *restrict format, ...);
 

説明

The strfmon() function formats the specified monetary amount according to the current locale and format specification format and places the result in the character array s of size bytes.

The strfmon_l() function performs the same task, but uses the locale specified by l. The behavior of strfmon_l() is undefined if l is the special locale object LC_GLOBAL_LOCALE (see duplocale(3)) or is not a valid locale object handle.

Ordinary characters in format are copied to s without conversion. Conversion specifiers are introduced by a '%' character. Immediately following it there can be zero or more of the following flags:

=f
1 バイト文字 f を数値埋め文字 (numeric fill character) にする (左精度と共に用いる。以下を参照)。 指定されないと、スペース文字が用いられる。
^
現在のロケールで定義されているであろうグループ化文字 (grouping character) を一切使わない。デフォルトではグループ化は有効になっている。
( または +
( フラグは、負の数値を括弧で括ることを意味する。 + フラグは符号をデフォルトのように取り扱うことを意味する (すなわち数値の前にロケールの符号マークが置かれる。 例えば正ならなにもなく、負なら '-' を置く、など)。
!
通貨シンボルを省略する。
-
すべてのフィールドを左詰めにする。デフォルトは右詰め。

次の位置には、フィールドの幅を指定できる。 10 進の数値文字列で、フィールドの最小幅をバイト単位で指定する。 デフォルトは 0。 結果がこの幅よりも狭くなった場合には、 不足分がスペースで埋められる (左詰めフラグが指定されていなければ左側が埋められる)。

次の位置には、"#" に 10 進数値文字列を続けた形式で、 左精度 (left precision) を指定できる。 通貨の基数点 (radix) より左側の数値の桁数がこの指定より小さい場合は、 数値埋め文字で左側が埋められる。 このフィールド幅の指定では、グループ化文字はカウントされない。

次の位置には、"." に 10 進数値文字列を続けた形式で、 右精度 (right precision) を指定できる。 整形される数値は、整形前にこの桁数に丸められる。 デフォルトではカレントロケールの frac_digits と int_frac_digits の指定を用いる。 右精度が 0 の場合は、基数点文字 (radix character) は印字されない (ここでの基数点文字は LC_MONETARY で定義されており、 LC_NUMERIC の指定とは異なっていてもよい)。

最後に、変換指定は変換文字 (conversion character) で終了しなければならない。 変換文字には以下の 3 つがある。

%
(In this case, the entire specification must be exactly "%%".) Put a '%' character in the result string.
i
double 型の引数ひとつが、 ロケールの国際通貨フォーマット (international currency format) を用いて変換される。
n
double 型の引数ひとつが、 ロケールの国内通貨フォーマット (national currency format) を用いて変換される。
 

返り値

strfmon() 関数は、結果の文字列が終端のヌルバイトを含めて配列 s に収まった場合には、 s に書きこまれた文字数を返す。ヌルバイトは文字数に入らない。 それ以外の場合には、 errno に E2BIG を設定して -1 を返す。 この場合の配列の内容は未定義である。  

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース属性値
strfmon() Thread safetyMT-Safe locale
strfmon_l() Thread safetyMT-Safe
 

標準規格

POSIX.1-2008.  

歴史

POSIX.1-2001.  

例

次のような関数コール

strfmon(buf, sizeof(buf), "[%^=*#6n] [%=*#6i]",
        1234.567, 1234.567);

は、オランダのロケールでは以下のような出力になる。

[€ **1234,57] [EUR **1 234,57]

in the nl_NL locale. The de_DE, de_CH, en_AU, and en_GB locales yield

[ **1234,57 €] [ **1.234,57 EUR]
[ Fr. **1234.57] [ CHF **1'234.57]
[ $**1234.57] [ AUD**1,234.57]
[ £**1234.57] [ GBP**1,234.57]
 

関連項目

duplocale(3), setlocale(3), sprintf(3), locale(7)


 

Index

名前
ライブラリ
書式
説明
返り値
属性
標準規格
歴史
例
関連項目

This document was created by man2html, using the manual pages.