OSDN Git Service

(split) Import translated manuals from JM CVS Repository.
[linuxjm/LDP_man-pages.git] / original / 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 \(aq%\(aq
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, for example, nothing for positive, "\-" for negative.
63 .TP
64 .B !
65 Omit the currency symbol.
66 .TP
67 .B \-
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
95 .BR LC_MONETARY ,
96 and may differ from that specified by
97 .BR LC_NUMERIC .)
98 .LP
99 Finally, the conversion specification must be ended with a
100 conversion character.
101 The three conversion characters are
102 .TP
103 .B %
104 (In this case the entire specification must be exactly "%%".)
105 Put a \(aq%\(aq character in the result string.
106 .TP
107 .B i
108 One argument of type
109 .I double
110 is converted using the locale's international currency format.
111 .TP
112 .B n
113 One argument of type
114 .I double
115 is converted using the locale's national currency format.
116 .SH "RETURN VALUE"
117 The
118 .BR strfmon ()
119 function returns the number of characters placed
120 in the array \fIs\fP, not including the terminating null byte,
121 provided the string, including the terminating null byte, fits.
122 Otherwise, it sets
123 .I errno
124 to
125 .BR E2BIG ,
126 returns \-1, and the contents of the array is undefined.
127 .SH "CONFORMING TO"
128 Not in POSIX.1-2001.
129 Present on several other systems.
130 .SH EXAMPLE
131 The call
132 .in +4n
133 .nf
134
135 strfmon(buf, sizeof(buf), "[%^=*#6n] [%=*#6i]",
136         1234.567, 1234.567);
137
138 .fi
139 .in
140 outputs
141 .in +4n
142
143 [ fl **1234,57] [ NLG  **1 234,57]
144
145 .in
146 in the Dutch locale (with fl for "florijnen" and NLG for Netherlands Guilders).
147 The grouping character is very ugly because it takes as much space
148 as a digit, while it should not take more than half that,
149 and will no doubt cause confusion.
150 Surprisingly, the "fl" is preceded and followed by a space,
151 and "NLG" is preceded by one and followed by two spaces.
152 This may be a bug in the locale files.
153 The Italian, Australian, Swiss
154 and Portuguese locales yield
155 .in +4n
156
157 [ L. **1235] [ ITL  **1.235]
158 .br
159 [ $**1234.57] [ AUD **1,234.57]
160 .br
161 [Fr. **1234,57] [CHF  **1.234,57]
162 .br
163 [ **1234$57Esc] [ **1.234$57PTE ]
164 .in
165 .SH "SEE ALSO"
166 .BR setlocale (3),
167 .BR sprintf (3),
168 .BR locale (7)