PHP localeconv() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

In PHP, localeconv() returns an array with number and currency formatting rules for the current locale.

It takes no arguments. The values depend on what setlocale() has set.

Syntax

Call localeconv() with the values you need. Start with this line.

PHP
$info = localeconv();
CallWhat it does
localeconv()["decimal_point"]The character used before decimals, such as ".".
localeconv()["thousands_sep"]The character used between groups of digits.
localeconv()["currency_symbol"]The local currency symbol, such as "$".

The array also holds keys like int_curr_symbol, mon_decimal_point, positive_sign, and negative_sign.

Library declarations
PHP
localeconv(): array

Parameters

ParameterDescription

Return Value

Return ValueDescription
arrayAn associative array of locale formatting values.

PHP Examples

Example 1 — Read the Decimal Point and Separator

Set the locale, then read the two most used keys.

PHP
<?php
setlocale(LC_ALL, "C");
$loc = localeconv();

echo "Decimal point: " . $loc["decimal_point"], PHP_EOL;
echo "Thousands sep: '" . $loc["thousands_sep"] . "'", PHP_EOL;

How It Works

  1. Set a locale. The "C" locale is the plain default.
  2. Call localeconv. It returns an array.
  3. Read decimal_point. In the C locale it is a dot.
  4. Read thousands_sep. It is empty, so the quotes show nothing between them.

Example 2 — Empty Currency Values in the C Locale

Some keys are empty strings when the locale has no currency rules.

PHP
<?php
setlocale(LC_ALL, "C");
$loc = localeconv();

var_dump($loc["currency_symbol"]);
var_dump($loc["thousands_sep"]);

How It Works

  1. Use the C locale. It has no currency details.
  2. Read currency_symbol. It is an empty string.
  3. Read thousands_sep. It is also empty.
  4. Plan a fallback. Always handle empty values in your own code.

Example 3 — Format a Number with Locale Values

Feed the locale separators into number_format() with a safe fallback.

PHP
<?php
setlocale(LC_ALL, "C");
$loc = localeconv();

$number = 1234567.891;
$thousands = $loc["thousands_sep"] ?: ",";

echo number_format($number, 2, $loc["decimal_point"], $thousands), PHP_EOL;

How It Works

  1. Get the locale data. Use decimal_point and thousands_sep.
  2. Add a fallback. The ?: operator uses a comma when the value is empty.
  3. Pass them to number_format. The separators are the 3rd and 4th arguments.
  4. Print the result. You get 1,234,567.89.

Frequently Asked Questions

localeconv() returns an associative array of numeric and monetary formatting information for the current locale, such as the decimal point and currency symbol.
array localeconv(). It has no parameters.
PHP starts in the "C" locale, which has almost no regional rules. Call setlocale() with a real locale first, and make sure that locale is installed on the server.
No. It only reads the current settings. Use setlocale() to change them.
For simple needs localeconv() with number_format() works. For full, reliable formatting across languages, the intl NumberFormatter class is the better choice.

Next: ltrim()

ltrim() removes whitespace, or other characters you choose, from the start of a string.

ltrim() tutorial →

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