Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

<locale.h> — locale settings

The <locale.h> header provides locale selection and information about formatting numbers and monetary amounts.

Version: C23; repository compiler flag, production runtime not attested

Syntax

#include <locale.h>
char *setlocale(int category, const char *locale);
struct lconv *localeconv(void);

<locale.h> provides setlocale and localeconv. The localeconv function returns a pointer to struct lconv.

Categories: LC_ALL — all; LC_COLLATE — strcoll/strxfrm; LC_CTYPE — character handling and multibyte conversions; LC_MONETARY — monetary information; LC_NUMERIC — decimal separator and nonmonetary information; LC_TIME — strftime/wcsftime.

In setlocale, "C" selects portable settings, "" the native environment, and NULL queries current settings. Failure returns NULL without changing settings. Changes can cause data races.

Do not modify the localeconv result; subsequent calls or relevant locale changes can overwrite it.

Examples

#include <locale.h>
#include <stdio.h>

int main(void)
{
    if (setlocale(LC_ALL, "C") == NULL) {
        return 1;
    }

    const struct lconv *info = localeconv();
    printf("decimal_point=%s\n", info->decimal_point);
    printf("value=%.2f\n", 1234.5);
    return 0;
}

Result

decimal_point=.
value=1234.50

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources