]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/strfmon.3
man*/: ffix (un-bracket tables)
[thirdparty/man-pages.git] / man3 / strfmon.3
1 '\" t
2 .\" Copyright (c) 2000 Andries Brouwer (aeb@cwi.nl)
3 .\"
4 .\" SPDX-License-Identifier: GPL-2.0-or-later
5 .\"
6 .TH strfmon 3 (date) "Linux man-pages (unreleased)"
7 .SH NAME
8 strfmon, strfmon_l \- convert monetary value to a string
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc ", " \-lc )
12 .SH SYNOPSIS
13 .nf
14 .B #include <monetary.h>
15 .PP
16 .BI "ssize_t strfmon(char " s "[restrict ." max "], size_t " max ,
17 .BI " const char *restrict " format ", ...);"
18 .BI "ssize_t strfmon_l(char " s "[restrict ." max "], size_t " max ", \
19 locale_t " locale ,
20 .BI " const char *restrict " format ", ...);"
21 .fi
22 .SH DESCRIPTION
23 The
24 .BR strfmon ()
25 function formats the specified monetary amount
26 according to the current locale
27 and format specification
28 .I format
29 and places the
30 result in the character array
31 .I s
32 of size
33 .IR max .
34 .PP
35 The
36 .BR strfmon_l ()
37 function performs the same task,
38 but uses
39 the locale specified by
40 .IR locale .
41 The behavior of
42 .BR strfmon_l ()
43 is undefined if
44 .I locale
45 is the special locale object
46 .B LC_GLOBAL_LOCALE
47 (see
48 .BR duplocale (3))
49 or is not a valid locale object handle.
50 .PP
51 Ordinary characters in
52 .I format
53 are copied to
54 .I s
55 without conversion.
56 Conversion specifiers are introduced by a \[aq]%\[aq]
57 character.
58 Immediately following it there can be zero or more
59 of the following flags:
60 .TP
61 .BI = f
62 The single-byte character
63 .I f
64 is used as the numeric fill character (to be used with
65 a left precision, see below).
66 When not specified, the space character is used.
67 .TP
68 .B \[ha]
69 Do not use any grouping characters that might be defined
70 for the current locale.
71 By default, grouping is enabled.
72 .TP
73 .BR ( " or " +
74 The ( flag indicates that negative amounts should be enclosed between
75 parentheses.
76 The + flag indicates that signs should be handled
77 in the default way, that is, amounts are preceded by the locale's
78 sign indication, for example, nothing for positive, "\-" for negative.
79 .TP
80 .B !
81 Omit the currency symbol.
82 .TP
83 .B \-
84 Left justify all fields.
85 The default is right justification.
86 .PP
87 Next, there may be a field width: a decimal digit string specifying
88 a minimum field width in bytes.
89 The default is 0.
90 A result smaller than this width is padded with spaces
91 (on the left, unless the left-justify flag was given).
92 .PP
93 Next, there may be a left precision of the form "#" followed by
94 a decimal digit string.
95 If the number of digits left of the
96 radix character is smaller than this, the representation is
97 padded on the left with the numeric fill character.
98 Grouping characters are not counted in this field width.
99 .PP
100 Next, there may be a right precision of the form "." followed by
101 a decimal digit string.
102 The amount being formatted is rounded to
103 the specified number of digits prior to formatting.
104 The default is specified in the
105 .I frac_digits
106 and
107 .I int_frac_digits
108 items of the current locale.
109 If the right precision is 0, no radix character is printed.
110 (The radix character here is determined by
111 .BR LC_MONETARY ,
112 and may differ from that specified by
113 .BR LC_NUMERIC .)
114 .PP
115 Finally, the conversion specification must be ended with a
116 conversion character.
117 The three conversion characters are
118 .TP
119 .B %
120 (In this case, the entire specification must be exactly "%%".)
121 Put a \[aq]%\[aq] character in the result string.
122 .TP
123 .B i
124 One argument of type
125 .I double
126 is converted using the locale's international currency format.
127 .TP
128 .B n
129 One argument of type
130 .I double
131 is converted using the locale's national currency format.
132 .SH RETURN VALUE
133 The
134 .BR strfmon ()
135 function returns the number of characters placed
136 in the array
137 .IR s ,
138 not including the terminating null byte,
139 provided the string, including the terminating null byte, fits.
140 Otherwise, it sets
141 .I errno
142 to
143 .BR E2BIG ,
144 returns \-1, and the contents of the array is undefined.
145 .SH ATTRIBUTES
146 For an explanation of the terms used in this section, see
147 .BR attributes (7).
148 .TS
149 allbox;
150 lbx lb lb
151 l l l.
152 Interface Attribute Value
153 T{
154 .na
155 .nh
156 .BR strfmon ()
157 T} Thread safety MT-Safe locale
158 T{
159 .na
160 .nh
161 .BR strfmon_l ()
162 T} Thread safety MT-Safe
163 .TE
164 .sp 1
165 .SH STANDARDS
166 POSIX.1-2008.
167 .SH HISTORY
168 POSIX.1-2001.
169 .SH EXAMPLES
170 The call
171 .PP
172 .in +4n
173 .EX
174 strfmon(buf, sizeof(buf), "[%\[ha]=*#6n] [%=*#6i]",
175 1234.567, 1234.567);
176 .EE
177 .in
178 .PP
179 outputs
180 .PP
181 .in +4n
182 .EX
183 [€ **1234,57] [EUR **1 234,57]
184 .EE
185 .in
186 .PP
187 in the
188 .I nl_NL
189 locale.
190 The
191 .IR de_DE ,
192 .IR de_CH ,
193 .IR en_AU ,
194 and
195 .I en_GB
196 locales yield
197 .PP
198 .in +4n
199 .EX
200 [ **1234,57 €] [ **1.234,57 EUR]
201 [ Fr. **1234.57] [ CHF **1\[aq]234.57]
202 [ $**1234.57] [ AUD**1,234.57]
203 [ £**1234.57] [ GBP**1,234.57]
204 .EE
205 .in
206 .SH SEE ALSO
207 .BR duplocale (3),
208 .BR setlocale (3),
209 .BR sprintf (3),
210 .BR locale (7)