]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/strfmon.3
tsearch.3: Minor tweak to Florian's patch
[thirdparty/man-pages.git] / man3 / strfmon.3
CommitLineData
fea681da
MK
1.\" Copyright (c) 2000 Andries Brouwer (aeb@cwi.nl)
2.\"
1dd72f9c 3.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
fea681da
MK
4.\" This is free documentation; you can redistribute it and/or
5.\" modify it under the terms of the GNU General Public License as
6.\" published by the Free Software Foundation; either version 2 of
7.\" the License, or (at your option) any later version.
8.\"
9.\" The GNU General Public License's references to "object code"
10.\" and "executables" are to be interpreted as the output of any
11.\" document formatting or typesetting system, including
12.\" intermediate and printed output.
13.\"
14.\" This manual is distributed in the hope that it will be useful,
15.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17.\" GNU General Public License for more details.
18.\"
19.\" You should have received a copy of the GNU General Public
c715f741
MK
20.\" License along with this manual; if not, see
21.\" <http://www.gnu.org/licenses/>.
6a8d8745 22.\" %%%LICENSE_END
fea681da 23.\"
4b8c67d9 24.TH STRFMON 3 2017-09-15 "Linux" "Linux Programmer's Manual"
fea681da 25.SH NAME
88b801ec 26strfmon, strfmon_l \- convert monetary value to a string
fea681da 27.SH SYNOPSIS
88b801ec 28.nf
fea681da 29.B #include <monetary.h>
68e4db0a 30.PP
fea681da
MK
31.BI "ssize_t strfmon(char *" s ", size_t " max ", const char *" format ,
32.B "...);"
dbfe9c70 33.PP
8cc4d071 34.BI "ssize_t strfmon_l(char *" s ", size_t " max ", locale_t " locale ",
88b801ec
MM
35.B const char *" format , "...);"
36.fi
fea681da 37.SH DESCRIPTION
60a90ecd
MK
38The
39.BR strfmon ()
88b801ec
MM
40function formats the specified monetary amount
41according to the current locale
42and format specification
c6fa0841
MK
43.I format
44and places the
45result in the character array
46.I s
47of size
48.IR max .
847e0d88 49.PP
88b801ec
MM
50The
51.BR strfmon_l ()
52function performs the same task,
53but uses
54the locale specified by
55.IR locale .
56The behavior of
57.BR strfmon_l ()
58is undefined if
59.I locale
60is the special locale object
61.BR LC_GLOBAL_LOCALE
62(see
63.BR duplocale (3))
64or is not a valid locale object handle.
fea681da 65.PP
c6fa0841
MK
66Ordinary characters in
67.I format
68are copied to
69.I s
c13182ef 70without conversion.
f81fb444 71Conversion specifiers are introduced by a \(aq%\(aq
c13182ef
MK
72character.
73Immediately following it there can be zero or more
fea681da
MK
74of the following flags:
75.TP
76.BI = f
77The single-byte character
78.I f
79is used as the numeric fill character (to be used with
80a left precision, see below).
81When not specified, the space character is used.
82.TP
83.B ^
84Do not use any grouping characters that might be defined
c13182ef
MK
85for the current locale.
86By default, grouping is enabled.
fea681da
MK
87.TP
88.BR ( " or " +
89The ( flag indicates that negative amounts should be enclosed between
c13182ef
MK
90parentheses.
91The + flag indicates that signs should be handled
fea681da 92in the default way, that is, amounts are preceded by the locale's
75b94dc3 93sign indication, for example, nothing for positive, "\-" for negative.
fea681da 94.TP
0daa9e92 95.B !
fea681da
MK
96Omit the currency symbol.
97.TP
0daa9e92 98.B \-
c13182ef
MK
99Left justify all fields.
100The default is right justification.
dd3568a1 101.PP
fea681da 102Next, there may be a field width: a decimal digit string specifying
c13182ef
MK
103a minimum field width in bytes.
104The default is 0.
fea681da
MK
105A result smaller than this width is padded with spaces
106(on the left, unless the left-justify flag was given).
dd3568a1 107.PP
fea681da 108Next, there may be a left precision of the form "#" followed by
c13182ef
MK
109a decimal digit string.
110If the number of digits left of the
fea681da
MK
111radix character is smaller than this, the representation is
112padded on the left with the numeric fill character.
113Grouping characters are not counted in this field width.
dd3568a1 114.PP
fea681da 115Next, there may be a right precision of the form "." followed by
c13182ef
MK
116a decimal digit string.
117The amount being formatted is rounded to
fea681da
MK
118the specified number of digits prior to formatting.
119The default is specified in the
120.I frac_digits
121and
122.I int_frac_digits
123items of the current locale.
124If the right precision is 0, no radix character is printed.
097585ed 125(The radix character here is determined by
74d32233 126.BR LC_MONETARY ,
097585ed
MK
127and may differ from that specified by
128.BR LC_NUMERIC .)
dd3568a1 129.PP
fea681da 130Finally, the conversion specification must be ended with a
c13182ef
MK
131conversion character.
132The three conversion characters are
fea681da
MK
133.TP
134.B %
6be6892b 135(In this case, the entire specification must be exactly "%%".)
f81fb444 136Put a \(aq%\(aq character in the result string.
fea681da
MK
137.TP
138.B i
6d275e3c
MK
139One argument of type
140.I double
141is converted using the locale's international currency format.
fea681da
MK
142.TP
143.B n
6d275e3c
MK
144One argument of type
145.I double
146is converted using the locale's national currency format.
47297adb 147.SH RETURN VALUE
60a90ecd
MK
148The
149.BR strfmon ()
150function returns the number of characters placed
c6fa0841
MK
151in the array
152.IR s ,
153not including the terminating null byte,
28d88c17 154provided the string, including the terminating null byte, fits.
fea681da
MK
155Otherwise, it sets
156.I errno
097585ed
MK
157to
158.BR E2BIG ,
159returns \-1, and the contents of the array is undefined.
ab7f7613
MS
160.SH ATTRIBUTES
161For an explanation of the terms used in this section, see
162.BR attributes (7).
163.TS
164allbox;
165lb lb lb
166l l l.
167Interface Attribute Value
168T{
169.BR strfmon ()
170T} Thread safety MT-Safe locale
88b801ec
MM
171T{
172.BR strfmon_l ()
173T} Thread safety MT-Safe
ab7f7613 174.TE
847e0d88 175.sp 1
47297adb 176.SH CONFORMING TO
64b17dcb 177POSIX.1-2001, POSIX.1-2008.
fea681da
MK
178.SH EXAMPLE
179The call
75b8c5b9 180.PP
a6e2f128 181.in +4n
75b8c5b9 182.EX
fea681da
MK
183strfmon(buf, sizeof(buf), "[%^=*#6n] [%=*#6i]",
184 1234.567, 1234.567);
75b8c5b9 185.EE
a6e2f128 186.in
75b8c5b9 187.PP
fea681da 188outputs
847e0d88 189.PP
75b8c5b9
MK
190.in +4n
191.EX
be1e94af 192[€ **1234,57] [EUR **1 234,57]
75b8c5b9 193.EE
a6e2f128 194.in
75b8c5b9 195.PP
be1e94af
MM
196in the
197.I nl_NL
198locale.
8cc4d071 199The
be1e94af
MM
200.IR de_DE ,
201.IR de_CH ,
202.IR en_AU ,
203and
204.I en_GB
205locales yield
847e0d88 206.PP
75b8c5b9
MK
207.in +4n
208.EX
be1e94af 209[ **1234,57 €] [ **1.234,57 EUR]
be1e94af 210[ Fr. **1234.57] [ CHF **1'234.57]
be1e94af 211[ $**1234.57] [ AUD**1,234.57]
be1e94af 212[ £**1234.57] [ GBP**1,234.57]
75b8c5b9 213.EE
a6e2f128 214.in
47297adb 215.SH SEE ALSO
88b801ec 216.BR duplocale (3),
fea681da
MK
217.BR setlocale (3),
218.BR sprintf (3),
219.BR locale (7)