C Locales

Beginner
7 min read
Updated: Nov 2026
1 example
<locale.h>

What Is a Locale in C?

A locale is a package of cultural conventions: how numbers look, how dates are written, how text is compared, and related rules. The <locale.h> header lets a beginner change those rules with setlocale() and inspect numeric formatting with localeconv().

Programs start in the portable C locale. That keeps behavior predictable. If you want the user’s environment settings, call setlocale(LC_ALL, "") and check for NULL.

Key idea.

Use the C locale for portable parsing and printing. Switch only when you truly need local conventions.

Common Locale Categories

MacroTypical meaning
LC_ALLEvery category at once.
LC_NUMERICNumber formatting rules.
LC_TIMEDate and time formatting.
LC_CTYPECharacter classification and case.
LC_COLLATEString comparison / sorting rules.
LC_MONETARYCurrency formatting rules.

The Set and Read Pattern

  1. Decide the locale. Prefer "C" for portable work, or "" for the environment.
  2. Call setlocale(). Check for NULL before continuing.
  3. Read fields if needed. Use localeconv() for decimal_point and related values.
  4. Copy what you keep. Static lconv data can change after another locale switch.

Starter: Set C Locale and Read decimal_point

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

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

    struct lconv *lc = localeconv();
    printf("locale = %s\n", setlocale(LC_ALL, NULL));
    printf("decimal_point = \"%s\"\n", lc->decimal_point);
    return 0;
}

How It Works

  1. Set the C locale. setlocale(LC_ALL, "C") selects portable rules.
  2. Check for failure. A NULL result means the request did not apply.
  3. Read formatting fields. localeconv() returns the active lconv record.
  4. Print decimal_point. In the C locale this is normally a dot.

Open the Function Guides

Frequently Asked Questions

A locale is a set of cultural conventions for numbers, dates, collation, and related behavior. locale.h lets a program set or query those rules.
The portable default. Select it with setlocale(LC_ALL, "C"). Programs start there.
setlocale(category, "") asks for the environment locale from LANG / LC_*.
Learn setlocale() to change or query, then localeconv() to read formatting fields.
No. Names and available locales depend on the operating system. Always check for NULL.

Browse locale.h functions

Open setlocale() and localeconv() with full examples.

Function index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful