]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/strfmon.3
9c7a4013d6125ea8261dd4ed6792d7cf53a28239
[thirdparty/man-pages.git] / man3 / strfmon.3
1 .\" Copyright (c) 2000 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" This is free documentation; you can redistribute it and/or
4 .\" modify it under the terms of the GNU General Public License as
5 .\" published by the Free Software Foundation; either version 2 of
6 .\" the License, or (at your option) any later version.
7 .\"
8 .\" The GNU General Public License's references to "object code"
9 .\" and "executables" are to be interpreted as the output of any
10 .\" document formatting or typesetting system, including
11 .\" intermediate and printed output.
12 .\"
13 .\" This manual is distributed in the hope that it will be useful,
14 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
15 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 .\" GNU General Public License for more details.
17 .\"
18 .\" You should have received a copy of the GNU General Public
19 .\" License along with this manual; if not, write to the Free
20 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
21 .\" USA.
22 .\"
23 .TH STRFMON 3 2000-12-05 "Linux" "Linux Programmer's Manual"
24 .SH NAME
25 strfmon \- convert monetary value to a string
26 .SH SYNOPSIS
27 .B #include <monetary.h>
28 .sp
29 .BI "ssize_t strfmon(char *" s ", size_t " max ", const char *" format ,
30 .B "...);"
31 .SH DESCRIPTION
32 The
33 .BR strfmon ()
34 function formats the specified amounts
35 according to the format specification \fIformat\fP and places the
36 result in the character array \fIs\fP of size \fImax\fP.
37 .PP
38 Ordinary characters in \fIformat\fP are copied to \fIs\fP
39 without conversion.
40 Conversion specifiers are introduced by a `%'
41 character.
42 Immediately following it there can be zero or more
43 of the following flags:
44 .TP
45 .BI = f
46 The single-byte character
47 .I f
48 is used as the numeric fill character (to be used with
49 a left precision, see below).
50 When not specified, the space character is used.
51 .TP
52 .B ^
53 Do not use any grouping characters that might be defined
54 for the current locale.
55 By default, grouping is enabled.
56 .TP
57 .BR ( " or " +
58 The ( flag indicates that negative amounts should be enclosed between
59 parentheses.
60 The + flag indicates that signs should be handled
61 in the default way, that is, amounts are preceded by the locale's
62 sign indication, e.g., nothing for positive, "\-" for negative.
63 .TP
64 .BR !
65 Omit the currency symbol.
66 .TP
67 .BR \-
68 Left justify all fields.
69 The default is right justification.
70 .LP
71 Next, there may be a field width: a decimal digit string specifying
72 a minimum field width in bytes.
73 The default is 0.
74 A result smaller than this width is padded with spaces
75 (on the left, unless the left-justify flag was given).
76 .LP
77 Next, there may be a left precision of the form "#" followed by
78 a decimal digit string.
79 If the number of digits left of the
80 radix character is smaller than this, the representation is
81 padded on the left with the numeric fill character.
82 Grouping characters are not counted in this field width.
83 .LP
84 Next, there may be a right precision of the form "." followed by
85 a decimal digit string.
86 The amount being formatted is rounded to
87 the specified number of digits prior to formatting.
88 The default is specified in the
89 .I frac_digits
90 and
91 .I int_frac_digits
92 items of the current locale.
93 If the right precision is 0, no radix character is printed.
94 (The radix character here is determined by LC_MONETARY, and may
95 differ from that specified by LC_NUMERIC.)
96 .LP
97 Finally, the conversion specification must be ended with a
98 conversion character.
99 The three conversion characters are
100 .TP
101 .B %
102 (In this case the entire specification must be exactly "%%".)
103 Put a `%' character in the result string.
104 .TP
105 .B i
106 One argument of type double is converted using the locale's
107 international currency format.
108 .TP
109 .B n
110 One argument of type double is converted using the locale's
111 national currency format.
112 .SH "RETURN VALUE"
113 The
114 .BR strfmon ()
115 function returns the number of characters placed
116 in the array \fIs\fP, not including the terminating null byte,
117 provided the string, including the terminating null byte, fits.
118 Otherwise, it sets
119 .I errno
120 to E2BIG, returns \-1, and the contents of the array is undefined.
121 .SH "CONFORMING TO"
122 Not in POSIX.1-2001.
123 Present on several other systems.
124 .SH EXAMPLE
125 The call
126 .RS
127 .nf
128
129 strfmon(buf, sizeof(buf), "[%^=*#6n] [%=*#6i]",
130 1234.567, 1234.567);
131
132 .fi
133 .RE
134 outputs
135 .RS
136
137 [ fl **1234,57] [ NLG **1 234,57]
138
139 .RE
140 in the Dutch locale (with fl for "florijnen" and NLG for Netherlands Guilders).
141 The grouping character is very ugly because it takes as much space
142 as a digit, while it should not take more than half that,
143 and will no doubt cause confusion.
144 Surprisingly, the "fl" is preceded and followed by a space,
145 and "NLG" is preceded by one and followed by two spaces.
146 This may be a bug in the locale files.
147 The Italian, Australian, Swiss
148 and Portuguese locales yield
149 .RS
150
151 [ L. **1235] [ ITL **1.235]
152 .br
153 [ $**1234.57] [ AUD **1,234.57]
154 .br
155 [Fr. **1234,57] [CHF **1.234,57]
156 .br
157 [ **1234$57Esc] [ **1.234$57PTE ]
158 .RE
159 .SH "SEE ALSO"
160 .BR setlocale (3),
161 .BR sprintf (3),
162 .BR locale (7)