Table of Contents

<locale.h>

<locale.h> controls culture-specific formatting: decimal separators, currency symbols, sorting order. By default programs run in the "C" locale (ASCII, . decimal); call setlocale(LC_ALL, "") to use the user's environment locale.

Be careful with LC_NUMERIC—changing the decimal separator can break parsing of machine-generated data.

Example

This example demonstrates how locale affects number formatting.

// compile: gcc -o localeexample localeexample.c
// run: ./localeexample
// description: show how locale affects formatting
 
#include <locale.h>
#include <stdio.h>
 
int main() {
    double pi = 3.141592;
 
    setlocale(LC_ALL, "C");
    printf("C locale: %f\n", pi);
 
    setlocale(LC_NUMERIC, "de_DE.UTF-8");
    printf("German locale: %f\n", pi);
 
    return 0;
}