]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/strfmon.3
Import of man-pages 1.70
[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 .nf
28 .B #include <monetary.h>
29 .sp
30 .BI "ssize_t strfmon(char *" s ", size_t " max ", const char *" format ,
31 .B "...);"
32 .fi
33 .SH DESCRIPTION
34 The \fBstrfmon()\fP 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. Conversion specifiers are introduced by a `%'
40 character. Immediately following it there can be zero or more
41 of the following flags:
42 .TP
43 .BI = f
44 The single-byte character
45 .I f
46 is used as the numeric fill character (to be used with
47 a left precision, see below).
48 When not specified, the space character is used.
49 .TP
50 .B ^
51 Do not use any grouping characters that might be defined
52 for the current locale. By default, grouping is enabled.
53 .TP
54 .BR ( " or " +
55 The ( flag indicates that negative amounts should be enclosed between
56 parentheses. The + flag indicates that signs should be handled
57 in the default way, that is, amounts are preceded by the locale's
58 sign indication, e.g., nothing for positive, "-" for negative.
59 .TP
60 .BR !
61 Omit the currency symbol.
62 .TP
63 .BR \-
64 Left justify all fields. The default is right justification.
65 .LP
66 Next, there may be a field width: a decimal digit string specifying
67 a minimum field width in bytes. The default is 0.
68 A result smaller than this width is padded with spaces
69 (on the left, unless the left-justify flag was given).
70 .LP
71 Next, there may be a left precision of the form "#" followed by
72 a decimal digit string. If the number of digits left of the
73 radix character is smaller than this, the representation is
74 padded on the left with the numeric fill character.
75 Grouping characters are not counted in this field width.
76 .LP
77 Next, there may be a right precision of the form "." followed by
78 a decimal digit string. The amount being formatted is rounded to
79 the specified number of digits prior to formatting.
80 The default is specified in the
81 .I frac_digits
82 and
83 .I int_frac_digits
84 items of the current locale.
85 If the right precision is 0, no radix character is printed.
86 (The radix character here is determined by LC_MONETARY, and may
87 differ from that specified by LC_NUMERIC.)
88 .LP
89 Finally, the conversion specification must be ended with a
90 conversion character. The three conversion characters are
91 .TP
92 .B %
93 (In this case the entire specification must be exactly "%%".)
94 Put a `%' character in the result string.
95 .TP
96 .B i
97 One argument of type double is converted using the locale's
98 international currency format.
99 .TP
100 .B n
101 One argument of type double is converted using the locale's
102 national currency format.
103 .SH "RETURN VALUE"
104 The \fBstrfmon()\fP function returns the number of characters placed
105 in the array \fIs\fP, not including the terminating NUL character,
106 provided the string, including the terminating NUL, fits.
107 Otherwise, it sets
108 .I errno
109 to E2BIG, returns \-1, and the contents of the array is undefined.
110 .SH EXAMPLE
111 The call
112 .RS
113 .nf
114 strfmon(buf, sizeof(buf), "[%^=*#6n] [%=*#6i]",
115 1234.567, 1234.567);
116 .fi
117 .RE
118 outputs
119 .RS
120 [ fl **1234,57] [ NLG **1 234,57]
121 .RE
122 in the Dutch locale (with fl for "florijnen" and NLG for Netherlands Guilders).
123 The grouping character is very ugly because it takes as much space
124 as a digit, while it should not take more than half that,
125 and will no doubt cause confusion.
126 Surprisingly, the "fl" is preceded and followed by a space,
127 and "NLG" is preceded by one and followed by two spaces.
128 This may be a bug in the locale files. The Italian, Australian, Swiss
129 and Portuguese locales yield
130 .RS
131 [ L. **1235] [ ITL **1.235]
132 .br
133 [ $**1234.57] [ AUD **1,234.57]
134 .br
135 [Fr. **1234,57] [CHF **1.234,57]
136 .br
137 [ **1234$57Esc] [ **1.234$57PTE ]
138 .RE
139 .SH "SEE ALSO"
140 .BR setlocale (3),
141 .BR sprintf (3),
142 .BR locale (7)