OSDN Git Service

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