]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/strfmon.3
time.1, _syscall.2, acct.2, getsockname.2, nanosleep.2, pciconfig_read.2, sched_get_p...
[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
MK
23.\"
24.TH STRFMON 3 2000-12-05 "Linux" "Linux Programmer's Manual"
25.SH NAME
26strfmon \- convert monetary value to a string
27.SH SYNOPSIS
fea681da
MK
28.B #include <monetary.h>
29.sp
30.BI "ssize_t strfmon(char *" s ", size_t " max ", const char *" format ,
31.B "...);"
fea681da 32.SH DESCRIPTION
60a90ecd
MK
33The
34.BR strfmon ()
35function formats the specified amounts
c6fa0841
MK
36according to the format specification
37.I format
38and places the
39result in the character array
40.I s
41of size
42.IR max .
fea681da 43.PP
c6fa0841
MK
44Ordinary characters in
45.I format
46are copied to
47.I s
c13182ef 48without conversion.
f81fb444 49Conversion specifiers are introduced by a \(aq%\(aq
c13182ef
MK
50character.
51Immediately following it there can be zero or more
fea681da
MK
52of the following flags:
53.TP
54.BI = f
55The single-byte character
56.I f
57is used as the numeric fill character (to be used with
58a left precision, see below).
59When not specified, the space character is used.
60.TP
61.B ^
62Do not use any grouping characters that might be defined
c13182ef
MK
63for the current locale.
64By default, grouping is enabled.
fea681da
MK
65.TP
66.BR ( " or " +
67The ( flag indicates that negative amounts should be enclosed between
c13182ef
MK
68parentheses.
69The + flag indicates that signs should be handled
fea681da 70in the default way, that is, amounts are preceded by the locale's
75b94dc3 71sign indication, for example, nothing for positive, "\-" for negative.
fea681da 72.TP
0daa9e92 73.B !
fea681da
MK
74Omit the currency symbol.
75.TP
0daa9e92 76.B \-
c13182ef
MK
77Left justify all fields.
78The default is right justification.
fea681da
MK
79.LP
80Next, there may be a field width: a decimal digit string specifying
c13182ef
MK
81a minimum field width in bytes.
82The default is 0.
fea681da
MK
83A result smaller than this width is padded with spaces
84(on the left, unless the left-justify flag was given).
85.LP
86Next, there may be a left precision of the form "#" followed by
c13182ef
MK
87a decimal digit string.
88If the number of digits left of the
fea681da
MK
89radix character is smaller than this, the representation is
90padded on the left with the numeric fill character.
91Grouping characters are not counted in this field width.
92.LP
93Next, there may be a right precision of the form "." followed by
c13182ef
MK
94a decimal digit string.
95The amount being formatted is rounded to
fea681da
MK
96the specified number of digits prior to formatting.
97The default is specified in the
98.I frac_digits
99and
100.I int_frac_digits
101items of the current locale.
102If the right precision is 0, no radix character is printed.
097585ed 103(The radix character here is determined by
74d32233 104.BR LC_MONETARY ,
097585ed
MK
105and may differ from that specified by
106.BR LC_NUMERIC .)
fea681da
MK
107.LP
108Finally, the conversion specification must be ended with a
c13182ef
MK
109conversion character.
110The three conversion characters are
fea681da
MK
111.TP
112.B %
113(In this case the entire specification must be exactly "%%".)
f81fb444 114Put a \(aq%\(aq character in the result string.
fea681da
MK
115.TP
116.B i
6d275e3c
MK
117One argument of type
118.I double
119is converted using the locale's international currency format.
fea681da
MK
120.TP
121.B n
6d275e3c
MK
122One argument of type
123.I double
124is converted using the locale's national currency format.
47297adb 125.SH RETURN VALUE
60a90ecd
MK
126The
127.BR strfmon ()
128function returns the number of characters placed
c6fa0841
MK
129in the array
130.IR s ,
131not including the terminating null byte,
28d88c17 132provided the string, including the terminating null byte, fits.
fea681da
MK
133Otherwise, it sets
134.I errno
097585ed
MK
135to
136.BR E2BIG ,
137returns \-1, and the contents of the array is undefined.
47297adb 138.SH CONFORMING TO
2b2581ee
MK
139Not in POSIX.1-2001.
140Present on several other systems.
fea681da
MK
141.SH EXAMPLE
142The call
a6e2f128 143.in +4n
fea681da 144.nf
b9f02710 145
fea681da
MK
146strfmon(buf, sizeof(buf), "[%^=*#6n] [%=*#6i]",
147 1234.567, 1234.567);
b9f02710 148
fea681da 149.fi
a6e2f128 150.in
fea681da 151outputs
a6e2f128 152.in +4n
b9f02710 153
fea681da 154[ fl **1234,57] [ NLG **1 234,57]
b9f02710 155
a6e2f128 156.in
fea681da
MK
157in the Dutch locale (with fl for "florijnen" and NLG for Netherlands Guilders).
158The grouping character is very ugly because it takes as much space
159as a digit, while it should not take more than half that,
160and will no doubt cause confusion.
161Surprisingly, the "fl" is preceded and followed by a space,
162and "NLG" is preceded by one and followed by two spaces.
c13182ef
MK
163This may be a bug in the locale files.
164The Italian, Australian, Swiss
fea681da 165and Portuguese locales yield
a6e2f128 166.in +4n
b9f02710 167
fea681da
MK
168[ L. **1235] [ ITL **1.235]
169.br
170[ $**1234.57] [ AUD **1,234.57]
171.br
172[Fr. **1234,57] [CHF **1.234,57]
173.br
174[ **1234$57Esc] [ **1.234$57PTE ]
a6e2f128 175.in
47297adb 176.SH SEE ALSO
fea681da
MK
177.BR setlocale (3),
178.BR sprintf (3),
179.BR locale (7)