]>
Commit | Line | Data |
---|---|---|
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 | |
25 | strfmon \- 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 |
60a90ecd MK |
32 | The |
33 | .BR strfmon () | |
34 | function formats the specified amounts | |
fea681da MK |
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 | |
c13182ef | 39 | without conversion. |
f81fb444 | 40 | Conversion specifiers are introduced by a \(aq%\(aq |
c13182ef MK |
41 | character. |
42 | Immediately following it there can be zero or more | |
fea681da MK |
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 | |
c13182ef MK |
54 | for the current locale. |
55 | By default, grouping is enabled. | |
fea681da MK |
56 | .TP |
57 | .BR ( " or " + | |
58 | The ( flag indicates that negative amounts should be enclosed between | |
c13182ef MK |
59 | parentheses. |
60 | The + flag indicates that signs should be handled | |
fea681da | 61 | in the default way, that is, amounts are preceded by the locale's |
75b94dc3 | 62 | sign indication, for example, nothing for positive, "\-" for negative. |
fea681da | 63 | .TP |
0daa9e92 | 64 | .B ! |
fea681da MK |
65 | Omit the currency symbol. |
66 | .TP | |
0daa9e92 | 67 | .B \- |
c13182ef MK |
68 | Left justify all fields. |
69 | The default is right justification. | |
fea681da MK |
70 | .LP |
71 | Next, there may be a field width: a decimal digit string specifying | |
c13182ef MK |
72 | a minimum field width in bytes. |
73 | The default is 0. | |
fea681da MK |
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 | |
c13182ef MK |
78 | a decimal digit string. |
79 | If the number of digits left of the | |
fea681da MK |
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 | |
c13182ef MK |
85 | a decimal digit string. |
86 | The amount being formatted is rounded to | |
fea681da MK |
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. | |
097585ed | 94 | (The radix character here is determined by |
74d32233 | 95 | .BR LC_MONETARY , |
097585ed MK |
96 | and may differ from that specified by |
97 | .BR LC_NUMERIC .) | |
fea681da MK |
98 | .LP |
99 | Finally, the conversion specification must be ended with a | |
c13182ef MK |
100 | conversion character. |
101 | The three conversion characters are | |
fea681da MK |
102 | .TP |
103 | .B % | |
104 | (In this case the entire specification must be exactly "%%".) | |
f81fb444 | 105 | Put a \(aq%\(aq character in the result string. |
fea681da MK |
106 | .TP |
107 | .B i | |
6d275e3c MK |
108 | One argument of type |
109 | .I double | |
110 | is converted using the locale's international currency format. | |
fea681da MK |
111 | .TP |
112 | .B n | |
6d275e3c MK |
113 | One argument of type |
114 | .I double | |
115 | is converted using the locale's national currency format. | |
47297adb | 116 | .SH RETURN VALUE |
60a90ecd MK |
117 | The |
118 | .BR strfmon () | |
119 | function returns the number of characters placed | |
28d88c17 MK |
120 | in the array \fIs\fP, not including the terminating null byte, |
121 | provided the string, including the terminating null byte, fits. | |
fea681da MK |
122 | Otherwise, it sets |
123 | .I errno | |
097585ed MK |
124 | to |
125 | .BR E2BIG , | |
126 | returns \-1, and the contents of the array is undefined. | |
47297adb | 127 | .SH CONFORMING TO |
2b2581ee MK |
128 | Not in POSIX.1-2001. |
129 | Present on several other systems. | |
fea681da MK |
130 | .SH EXAMPLE |
131 | The call | |
a6e2f128 | 132 | .in +4n |
fea681da | 133 | .nf |
b9f02710 | 134 | |
fea681da MK |
135 | strfmon(buf, sizeof(buf), "[%^=*#6n] [%=*#6i]", |
136 | 1234.567, 1234.567); | |
b9f02710 | 137 | |
fea681da | 138 | .fi |
a6e2f128 | 139 | .in |
fea681da | 140 | outputs |
a6e2f128 | 141 | .in +4n |
b9f02710 | 142 | |
fea681da | 143 | [ fl **1234,57] [ NLG **1 234,57] |
b9f02710 | 144 | |
a6e2f128 | 145 | .in |
fea681da MK |
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. | |
c13182ef MK |
152 | This may be a bug in the locale files. |
153 | The Italian, Australian, Swiss | |
fea681da | 154 | and Portuguese locales yield |
a6e2f128 | 155 | .in +4n |
b9f02710 | 156 | |
fea681da MK |
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 ] | |
a6e2f128 | 164 | .in |
47297adb | 165 | .SH SEE ALSO |
fea681da MK |
166 | .BR setlocale (3), |
167 | .BR sprintf (3), | |
168 | .BR locale (7) |