xref: /freebsd/lib/libc/locale/localeconv.3 (revision e0c4386e)
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.\" From FreeBSD: src/lib/libc/locale/setlocale.3,v 1.28 2003/11/15 02:26:04 tjr Exp
31.\"
32.Dd November 21, 2003
33.Dt LOCALECONV 3
34.Os
35.Sh NAME
36.Nm localeconv
37.Nd natural language formatting for C
38.Sh LIBRARY
39.Lb libc
40.Sh SYNOPSIS
41.In locale.h
42.Ft struct lconv *
43.Fn localeconv "void"
44.In xlocale.h
45.Ft struct lconv *
46.Fn localeconv_l "locale_t locale"
47.Sh DESCRIPTION
48The
49.Fn localeconv
50function returns a pointer to a structure
51which provides parameters for formatting numbers,
52especially currency values:
53.Bd -literal -offset indent
54struct lconv {
55	char	*decimal_point;
56	char	*thousands_sep;
57	char	*grouping;
58	char	*int_curr_symbol;
59	char	*currency_symbol;
60	char	*mon_decimal_point;
61	char	*mon_thousands_sep;
62	char	*mon_grouping;
63	char	*positive_sign;
64	char	*negative_sign;
65	char	int_frac_digits;
66	char	frac_digits;
67	char	p_cs_precedes;
68	char	p_sep_by_space;
69	char	n_cs_precedes;
70	char	n_sep_by_space;
71	char	p_sign_posn;
72	char	n_sign_posn;
73	char	int_p_cs_precedes;
74	char	int_n_cs_precedes;
75	char	int_p_sep_by_space;
76	char	int_n_sep_by_space;
77	char	int_p_sign_posn;
78	char	int_n_sign_posn;
79};
80.Ed
81.Pp
82The individual fields have the following meanings:
83.Bl -tag -width mon_decimal_point
84.It Va decimal_point
85The decimal point character, except for currency values,
86cannot be an empty string.
87.It Va thousands_sep
88The separator between groups of digits
89before the decimal point, except for currency values.
90.It Va grouping
91The sizes of the groups of digits, except for currency values.
92This is a pointer to a vector of integers, each of size
93.Vt char ,
94representing group size from low order digit groups
95to high order (right to left).
96The list may be terminated with 0 or
97.Dv CHAR_MAX .
98If the list is terminated with 0,
99the last group size before the 0 is repeated to account for all the digits.
100If the list is terminated with
101.Dv CHAR_MAX ,
102no more grouping is performed.
103.It Va int_curr_symbol
104The standardized international currency symbol.
105.It Va currency_symbol
106The local currency symbol.
107.It Va mon_decimal_point
108The decimal point character for currency values.
109.It Va mon_thousands_sep
110The separator for digit groups in currency values.
111.It Va mon_grouping
112Like
113.Va grouping
114but for currency values.
115.It Va positive_sign
116The character used to denote nonnegative currency values,
117usually the empty string.
118.It Va negative_sign
119The character used to denote negative currency values,
120usually a minus sign.
121.It Va int_frac_digits
122The number of digits after the decimal point
123in an international-style currency value.
124.It Va frac_digits
125The number of digits after the decimal point
126in the local style for currency values.
127.It Va p_cs_precedes
1281 if the currency symbol precedes the currency value
129for nonnegative values, 0 if it follows.
130.It Va p_sep_by_space
1311 if a space is inserted between the currency symbol
132and the currency value for nonnegative values, 0 otherwise.
133.It Va n_cs_precedes
134Like
135.Va p_cs_precedes
136but for negative values.
137.It Va n_sep_by_space
138Like
139.Va p_sep_by_space
140but for negative values.
141.It Va p_sign_posn
142The location of the
143.Va positive_sign
144with respect to a nonnegative quantity and the
145.Va currency_symbol ,
146coded as follows:
147.Pp
148.Bl -tag -width 3n -compact
149.It Li 0
150Parentheses around the entire string.
151.It Li 1
152Before the string.
153.It Li 2
154After the string.
155.It Li 3
156Just before
157.Va currency_symbol .
158.It Li 4
159Just after
160.Va currency_symbol .
161.El
162.It Va n_sign_posn
163Like
164.Va p_sign_posn
165but for negative currency values.
166.It Va int_p_cs_precedes
167Same as
168.Va p_cs_precedes ,
169but for internationally formatted monetary quantities.
170.It Va int_n_cs_precedes
171Same as
172.Va n_cs_precedes ,
173but for internationally formatted monetary quantities.
174.It Va int_p_sep_by_space
175Same as
176.Va p_sep_by_space ,
177but for internationally formatted monetary quantities.
178.It Va int_n_sep_by_space
179Same as
180.Va n_sep_by_space ,
181but for internationally formatted monetary quantities.
182.It Va int_p_sign_posn
183Same as
184.Va p_sign_posn ,
185but for internationally formatted monetary quantities.
186.It Va int_n_sign_posn
187Same as
188.Va n_sign_posn ,
189but for internationally formatted monetary quantities.
190.El
191.Pp
192Unless mentioned above,
193an empty string as a value for a field
194indicates a zero length result or
195a value that is not in the current locale.
196A
197.Dv CHAR_MAX
198result similarly denotes an unavailable value.
199.Pp
200The
201.Fn localeconv_l
202function takes an explicit locale parameter.
203For more information, see
204.Xr xlocale 3 .
205.Sh RETURN VALUES
206The
207.Fn localeconv
208function returns a pointer to a static object
209which may be altered by later calls to
210.Xr setlocale 3
211or
212.Fn localeconv .
213The return value for
214.Fn localeconv_l
215is stored with the locale.
216It will remain valid until a subsequent call to
217.Xr freelocale 3 .
218If a thread-local locale is in effect then the return value from
219.Fn localeconv
220will remain valid until the locale is destroyed.
221.Sh ERRORS
222No errors are defined.
223.Sh SEE ALSO
224.Xr setlocale 3 ,
225.Xr strfmon 3
226.Sh STANDARDS
227The
228.Fn localeconv
229function conforms to
230.St -isoC-99 .
231.Sh HISTORY
232The
233.Fn localeconv
234function first appeared in
235.Bx 4.4 .
236