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