xref: /freebsd/lib/libc/locale/localeconv.3 (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
1.\" Copyright (c) 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Donn Seeley at BSDI.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\" From @(#)setlocale.3	8.1 (Berkeley) 6/9/93
32.\" From FreeBSD: src/lib/libc/locale/setlocale.3,v 1.28 2003/11/15 02:26:04 tjr Exp
33.\"
34.Dd November 21, 2003
35.Dt LOCALECONV 3
36.Os
37.Sh NAME
38.Nm localeconv
39.Nd natural language formatting for C
40.Sh LIBRARY
41.Lb libc
42.Sh SYNOPSIS
43.In locale.h
44.Ft struct lconv *
45.Fn localeconv "void"
46.In xlocale.h
47.Ft struct lconv *
48.Fn localeconv_l "locale_t locale"
49.Sh DESCRIPTION
50The
51.Fn localeconv
52function returns a pointer to a structure
53which provides parameters for formatting numbers,
54especially currency values:
55.Bd -literal -offset indent
56struct lconv {
57	char	*decimal_point;
58	char	*thousands_sep;
59	char	*grouping;
60	char	*int_curr_symbol;
61	char	*currency_symbol;
62	char	*mon_decimal_point;
63	char	*mon_thousands_sep;
64	char	*mon_grouping;
65	char	*positive_sign;
66	char	*negative_sign;
67	char	int_frac_digits;
68	char	frac_digits;
69	char	p_cs_precedes;
70	char	p_sep_by_space;
71	char	n_cs_precedes;
72	char	n_sep_by_space;
73	char	p_sign_posn;
74	char	n_sign_posn;
75	char	int_p_cs_precedes;
76	char	int_n_cs_precedes;
77	char	int_p_sep_by_space;
78	char	int_n_sep_by_space;
79	char	int_p_sign_posn;
80	char	int_n_sign_posn;
81};
82.Ed
83.Pp
84The individual fields have the following meanings:
85.Bl -tag -width mon_decimal_point
86.It Va decimal_point
87The decimal point character, except for currency values,
88cannot be an empty string.
89.It Va thousands_sep
90The separator between groups of digits
91before the decimal point, except for currency values.
92.It Va grouping
93The sizes of the groups of digits, except for currency values.
94This is a pointer to a vector of integers, each of size
95.Vt char ,
96representing group size from low order digit groups
97to high order (right to left).
98The list may be terminated with 0 or
99.Dv CHAR_MAX .
100If the list is terminated with 0,
101the last group size before the 0 is repeated to account for all the digits.
102If the list is terminated with
103.Dv CHAR_MAX ,
104no more grouping is performed.
105.It Va int_curr_symbol
106The standardized international currency symbol.
107.It Va currency_symbol
108The local currency symbol.
109.It Va mon_decimal_point
110The decimal point character for currency values.
111.It Va mon_thousands_sep
112The separator for digit groups in currency values.
113.It Va mon_grouping
114Like
115.Va grouping
116but for currency values.
117.It Va positive_sign
118The character used to denote nonnegative currency values,
119usually the empty string.
120.It Va negative_sign
121The character used to denote negative currency values,
122usually a minus sign.
123.It Va int_frac_digits
124The number of digits after the decimal point
125in an international-style currency value.
126.It Va frac_digits
127The number of digits after the decimal point
128in the local style for currency values.
129.It Va p_cs_precedes
1301 if the currency symbol precedes the currency value
131for nonnegative values, 0 if it follows.
132.It Va p_sep_by_space
1331 if a space is inserted between the currency symbol
134and the currency value for nonnegative values, 0 otherwise.
135.It Va n_cs_precedes
136Like
137.Va p_cs_precedes
138but for negative values.
139.It Va n_sep_by_space
140Like
141.Va p_sep_by_space
142but for negative values.
143.It Va p_sign_posn
144The location of the
145.Va positive_sign
146with respect to a nonnegative quantity and the
147.Va currency_symbol ,
148coded as follows:
149.Pp
150.Bl -tag -width 3n -compact
151.It Li 0
152Parentheses around the entire string.
153.It Li 1
154Before the string.
155.It Li 2
156After the string.
157.It Li 3
158Just before
159.Va currency_symbol .
160.It Li 4
161Just after
162.Va currency_symbol .
163.El
164.It Va n_sign_posn
165Like
166.Va p_sign_posn
167but for negative currency values.
168.It Va int_p_cs_precedes
169Same as
170.Va p_cs_precedes ,
171but for internationally formatted monetary quantities.
172.It Va int_n_cs_precedes
173Same as
174.Va n_cs_precedes ,
175but for internationally formatted monetary quantities.
176.It Va int_p_sep_by_space
177Same as
178.Va p_sep_by_space ,
179but for internationally formatted monetary quantities.
180.It Va int_n_sep_by_space
181Same as
182.Va n_sep_by_space ,
183but for internationally formatted monetary quantities.
184.It Va int_p_sign_posn
185Same as
186.Va p_sign_posn ,
187but for internationally formatted monetary quantities.
188.It Va int_n_sign_posn
189Same as
190.Va n_sign_posn ,
191but for internationally formatted monetary quantities.
192.El
193.Pp
194Unless mentioned above,
195an empty string as a value for a field
196indicates a zero length result or
197a value that is not in the current locale.
198A
199.Dv CHAR_MAX
200result similarly denotes an unavailable value.
201.Pp
202The
203.Fn localeconv_l
204function takes an explicit locale parameter.
205For more information, see
206.Xr xlocale 3 .
207.Sh RETURN VALUES
208The
209.Fn localeconv
210function returns a pointer to a static object
211which may be altered by later calls to
212.Xr setlocale 3
213or
214.Fn localeconv .
215The return value for
216.Fn localeconv_l
217is stored with the locale.
218It will remain valid until a subsequent call to
219.Xr freelocale 3 .
220If a thread-local locale is in effect then the return value from
221.Fn localeconv
222will remain valid until the locale is destroyed.
223.Sh ERRORS
224No errors are defined.
225.Sh SEE ALSO
226.Xr setlocale 3 ,
227.Xr strfmon 3
228.Sh STANDARDS
229The
230.Fn localeconv
231function conforms to
232.St -isoC-99 .
233.Sh HISTORY
234The
235.Fn localeconv
236function first appeared in
237.Bx 4.4 .
238