1strfmon(3) Library Functions Manual strfmon(3)
2
3
4
6 strfmon, strfmon_l - convert monetary value to a string
7
9 Standard C library (libc, -lc)
10
12 #include <monetary.h>
13
14 ssize_t strfmon(char s[restrict .max], size_t max,
15 const char *restrict format, ...);
16 ssize_t strfmon_l(char s[restrict .max], size_t max, locale_t locale,
17 const char *restrict format, ...);
18
20 The strfmon() function formats the specified monetary amount according
21 to the current locale and format specification format and places the
22 result in the character array s of size max.
23
24 The strfmon_l() function performs the same task, but uses the locale
25 specified by locale. The behavior of strfmon_l() is undefined if lo‐
26 cale is the special locale object LC_GLOBAL_LOCALE (see duplocale(3))
27 or is not a valid locale object handle.
28
29 Ordinary characters in format are copied to s without conversion. Con‐
30 version specifiers are introduced by a '%' character. Immediately fol‐
31 lowing it there can be zero or more of the following flags:
32
33 =f The single-byte character f is used as the numeric fill charac‐
34 ter (to be used with a left precision, see below). When not
35 specified, the space character is used.
36
37 ^ Do not use any grouping characters that might be defined for the
38 current locale. By default, grouping is enabled.
39
40 ( or + The ( flag indicates that negative amounts should be enclosed
41 between parentheses. The + flag indicates that signs should be
42 handled in the default way, that is, amounts are preceded by the
43 locale's sign indication, for example, nothing for positive, "-"
44 for negative.
45
46 ! Omit the currency symbol.
47
48 - Left justify all fields. The default is right justification.
49
50 Next, there may be a field width: a decimal digit string specifying a
51 minimum field width in bytes. The default is 0. A result smaller than
52 this width is padded with spaces (on the left, unless the left-justify
53 flag was given).
54
55 Next, there may be a left precision of the form "#" followed by a deci‐
56 mal digit string. If the number of digits left of the radix character
57 is smaller than this, the representation is padded on the left with the
58 numeric fill character. Grouping characters are not counted in this
59 field width.
60
61 Next, there may be a right precision of the form "." followed by a dec‐
62 imal digit string. The amount being formatted is rounded to the speci‐
63 fied number of digits prior to formatting. The default is specified in
64 the frac_digits and int_frac_digits items of the current locale. If
65 the right precision is 0, no radix character is printed. (The radix
66 character here is determined by LC_MONETARY, and may differ from that
67 specified by LC_NUMERIC.)
68
69 Finally, the conversion specification must be ended with a conversion
70 character. The three conversion characters are
71
72 % (In this case, the entire specification must be exactly "%%".)
73 Put a '%' character in the result string.
74
75 i One argument of type double is converted using the locale's in‐
76 ternational currency format.
77
78 n One argument of type double is converted using the locale's na‐
79 tional currency format.
80
82 The strfmon() function returns the number of characters placed in the
83 array s, not including the terminating null byte, provided the string,
84 including the terminating null byte, fits. Otherwise, it sets errno to
85 E2BIG, returns -1, and the contents of the array is undefined.
86
88 For an explanation of the terms used in this section, see at‐
89 tributes(7).
90
91 ┌─────────────────────────────────────┬───────────────┬────────────────┐
92 │Interface │ Attribute │ Value │
93 ├─────────────────────────────────────┼───────────────┼────────────────┤
94 │strfmon() │ Thread safety │ MT-Safe locale │
95 ├─────────────────────────────────────┼───────────────┼────────────────┤
96 │strfmon_l() │ Thread safety │ MT-Safe │
97 └─────────────────────────────────────┴───────────────┴────────────────┘
98
100 POSIX.1-2008.
101
103 POSIX.1-2001.
104
106 The call
107
108 strfmon(buf, sizeof(buf), "[%^=*#6n] [%=*#6i]",
109 1234.567, 1234.567);
110
111 outputs
112
113 [€ **1234,57] [EUR **1 234,57]
114
115 in the nl_NL locale. The de_DE, de_CH, en_AU, and en_GB locales yield
116
117 [ **1234,57 €] [ **1.234,57 EUR]
118 [ Fr. **1234.57] [ CHF **1'234.57]
119 [ $**1234.57] [ AUD**1,234.57]
120 [ £**1234.57] [ GBP**1,234.57]
121
123 duplocale(3), setlocale(3), sprintf(3), locale(7)
124
125
126
127Linux man-pages 6.05 2023-07-20 strfmon(3)