| 1 |
'\" t |
| 2 |
.\" Copyright (c) 2000 Andries Brouwer ([email protected]) |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: GPL-2.0-or-later |
| 5 |
.\" |
| 6 |
.TH strfmon 3 2024-05-02 "Linux man-pages 6.9.1" |
| 7 |
.SH NAME |
| 8 |
strfmon, strfmon_l \- convert monetary value to a string |
| 9 |
.SH LIBRARY |
| 10 |
Standard C library |
| 11 |
.RI ( libc ", " \-lc ) |
| 12 |
.SH SYNOPSIS |
| 13 |
.nf |
| 14 |
.B #include <monetary.h> |
| 15 |
.P |
| 16 |
.BI "ssize_t strfmon(char " s "[restrict ." max "], size_t " max , |
| 17 |
.BI " const char *restrict " format ", ...);" |
| 18 |
.BI "ssize_t strfmon_l(char " s "[restrict ." max "], size_t " max ", \ |
| 19 |
locale_t " locale , |
| 20 |
.BI " const char *restrict " format ", ...);" |
| 21 |
.fi |
| 22 |
.SH DESCRIPTION |
| 23 |
The |
| 24 |
.BR strfmon () |
| 25 |
function formats the specified monetary amount |
| 26 |
according to the current locale |
| 27 |
and format specification |
| 28 |
.I format |
| 29 |
and places the |
| 30 |
result in the character array |
| 31 |
.I s |
| 32 |
of size |
| 33 |
.IR max . |
| 34 |
.P |
| 35 |
The |
| 36 |
.BR strfmon_l () |
| 37 |
function performs the same task, |
| 38 |
but uses |
| 39 |
the locale specified by |
| 40 |
.IR locale . |
| 41 |
The behavior of |
| 42 |
.BR strfmon_l () |
| 43 |
is undefined if |
| 44 |
.I locale |
| 45 |
is the special locale object |
| 46 |
.B LC_GLOBAL_LOCALE |
| 47 |
(see |
| 48 |
.BR duplocale (3)) |
| 49 |
or is not a valid locale object handle. |
| 50 |
.P |
| 51 |
Ordinary characters in |
| 52 |
.I format |
| 53 |
are copied to |
| 54 |
.I s |
| 55 |
without conversion. |
| 56 |
Conversion specifiers are introduced by a \[aq]%\[aq] |
| 57 |
character. |
| 58 |
Immediately following it there can be zero or more |
| 59 |
of the following flags: |
| 60 |
.TP |
| 61 |
.BI = f |
| 62 |
The single-byte character |
| 63 |
.I f |
| 64 |
is used as the numeric fill character (to be used with |
| 65 |
a left precision, see below). |
| 66 |
When not specified, the space character is used. |
| 67 |
.TP |
| 68 |
.B \[ha] |
| 69 |
Do not use any grouping characters that might be defined |
| 70 |
for the current locale. |
| 71 |
By default, grouping is enabled. |
| 72 |
.TP |
| 73 |
.BR ( " or " + |
| 74 |
The ( flag indicates that negative amounts should be enclosed between |
| 75 |
parentheses. |
| 76 |
The + flag indicates that signs should be handled |
| 77 |
in the default way, that is, amounts are preceded by the locale's |
| 78 |
sign indication, for example, nothing for positive, "\-" for negative. |
| 79 |
.TP |
| 80 |
.B ! |
| 81 |
Omit the currency symbol. |
| 82 |
.TP |
| 83 |
.B \- |
| 84 |
Left justify all fields. |
| 85 |
The default is right justification. |
| 86 |
.P |
| 87 |
Next, there may be a field width: a decimal digit string specifying |
| 88 |
a minimum field width in bytes. |
| 89 |
The default is 0. |
| 90 |
A result smaller than this width is padded with spaces |
| 91 |
(on the left, unless the left-justify flag was given). |
| 92 |
.P |
| 93 |
Next, there may be a left precision of the form "#" followed by |
| 94 |
a decimal digit string. |
| 95 |
If the number of digits left of the |
| 96 |
radix character is smaller than this, the representation is |
| 97 |
padded on the left with the numeric fill character. |
| 98 |
Grouping characters are not counted in this field width. |
| 99 |
.P |
| 100 |
Next, there may be a right precision of the form "." followed by |
| 101 |
a decimal digit string. |
| 102 |
The amount being formatted is rounded to |
| 103 |
the specified number of digits prior to formatting. |
| 104 |
The default is specified in the |
| 105 |
.I frac_digits |
| 106 |
and |
| 107 |
.I int_frac_digits |
| 108 |
items of the current locale. |
| 109 |
If the right precision is 0, no radix character is printed. |
| 110 |
(The radix character here is determined by |
| 111 |
.BR LC_MONETARY , |
| 112 |
and may differ from that specified by |
| 113 |
.BR LC_NUMERIC .) |
| 114 |
.P |
| 115 |
Finally, the conversion specification must be ended with a |
| 116 |
conversion character. |
| 117 |
The three conversion characters are |
| 118 |
.TP |
| 119 |
.B % |
| 120 |
(In this case, the entire specification must be exactly "%%".) |
| 121 |
Put a \[aq]%\[aq] character in the result string. |
| 122 |
.TP |
| 123 |
.B i |
| 124 |
One argument of type |
| 125 |
.I double |
| 126 |
is converted using the locale's international currency format. |
| 127 |
.TP |
| 128 |
.B n |
| 129 |
One argument of type |
| 130 |
.I double |
| 131 |
is converted using the locale's national currency format. |
| 132 |
.SH RETURN VALUE |
| 133 |
The |
| 134 |
.BR strfmon () |
| 135 |
function returns the number of characters placed |
| 136 |
in the array |
| 137 |
.IR s , |
| 138 |
not including the terminating null byte, |
| 139 |
provided the string, including the terminating null byte, fits. |
| 140 |
Otherwise, it sets |
| 141 |
.I errno |
| 142 |
to |
| 143 |
.BR E2BIG , |
| 144 |
returns \-1, and the contents of the array is undefined. |
| 145 |
.SH ATTRIBUTES |
| 146 |
For an explanation of the terms used in this section, see |
| 147 |
.BR attributes (7). |
| 148 |
.TS |
| 149 |
allbox; |
| 150 |
lbx lb lb |
| 151 |
l l l. |
| 152 |
Interface Attribute Value |
| 153 |
T{ |
| 154 |
.na |
| 155 |
.nh |
| 156 |
.BR strfmon () |
| 157 |
T} Thread safety MT-Safe locale |
| 158 |
T{ |
| 159 |
.na |
| 160 |
.nh |
| 161 |
.BR strfmon_l () |
| 162 |
T} Thread safety MT-Safe |
| 163 |
.TE |
| 164 |
.SH STANDARDS |
| 165 |
POSIX.1-2008. |
| 166 |
.SH HISTORY |
| 167 |
POSIX.1-2001. |
| 168 |
.SH EXAMPLES |
| 169 |
The call |
| 170 |
.P |
| 171 |
.in +4n |
| 172 |
.EX |
| 173 |
strfmon(buf, sizeof(buf), "[%\[ha]=*#6n] [%=*#6i]", |
| 174 |
1234.567, 1234.567); |
| 175 |
.EE |
| 176 |
.in |
| 177 |
.P |
| 178 |
outputs |
| 179 |
.P |
| 180 |
.in +4n |
| 181 |
.EX |
| 182 |
[€ **1234,57] [EUR **1 234,57] |
| 183 |
.EE |
| 184 |
.in |
| 185 |
.P |
| 186 |
in the |
| 187 |
.I nl_NL |
| 188 |
locale. |
| 189 |
The |
| 190 |
.IR de_DE , |
| 191 |
.IR de_CH , |
| 192 |
.IR en_AU , |
| 193 |
and |
| 194 |
.I en_GB |
| 195 |
locales yield |
| 196 |
.P |
| 197 |
.in +4n |
| 198 |
.EX |
| 199 |
[ **1234,57 €] [ **1.234,57 EUR] |
| 200 |
[ Fr. **1234.57] [ CHF **1\[aq]234.57] |
| 201 |
[ $**1234.57] [ AUD**1,234.57] |
| 202 |
[ £**1234.57] [ GBP**1,234.57] |
| 203 |
.EE |
| 204 |
.in |
| 205 |
.SH SEE ALSO |
| 206 |
.BR duplocale (3), |
| 207 |
.BR setlocale (3), |
| 208 |
.BR sprintf (3), |
| 209 |
.BR locale (7) |