C Programming/C Reference/locale.h
< C Programming < C ReferenceIn computing, locale.h is a C programming language header file, used for purposes of localization. The header provides two key functions: localeconv
and setlocale
. The former provides access to the current locale, while the latter allows one to set the current locale. The header also defines the struct lconv
, which stores information about a given locale, including the local preference for the display of numbers and currency.
Template:C Standard library
Usage
Inclusion
- C
#include <locale.h>
- C++
#include <clocale>
Functions and usage
struct lconv
explain formating monetary and other numeric values.
char* desimal point;
desimal point for non-monertary values
char* grouping;
size pf digit groups for non-monetary values
struct lconv* localeconv(void);
char* setlocale(int, const char*);
charthousand sep;
separator for non-monetary values
char* currency symbol;
currency symbol
char* int curr symbol;
international currency symbol
char*mon-decimal point
decimal point for monetary values
char* mon grouping;
sizes of digit groups for monetary values
char* mon thousand sep;
separator for digit groups for monetary values
Example
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main(void)
{
/* Locale is set to "C" before this. This call sets it
to the "current locale" by reading environment variables: */
setlocale(LC_ALL, "");
const struct lconv * const currentlocale = localeconv();
printf("In the current locale, the default currency symbol is: %s\n",
currentlocale->currency_symbol);
return EXIT_SUCCESS;
}
References
- ↑ "local.h". utas.edu.au. infosys. http://www.utas.edu.au/infosys/info/documentation/C/CStdLib.html#locale.h. Retrieved 14 September 2011.
- locale.h by OpenGroup
- localeconv by OpenGroup
- setlocale by OpenGroup
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.