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