Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

How to Format Data Based on Locale in Angular

Configure Angular’s locale-aware pipes with LOCALE_ID, register data for additional locales, and set explicit currency, precision, and timezone options when output must be predictable.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Angular’s locale-aware pipes—DatePipe, CurrencyPipe, DecimalPipe, and PercentPipe—to format values in templates. Set the application’s LOCALE_ID for a consistent default, register locale data for locales beyond en-US, and pass explicit options when a date, currency, or number must render predictably. In application code outside a template, use Angular’s standalone formatting functions.

How Angular chooses a locale

Angular’s built-in date, currency, decimal, and percent pipes use locale conventions through LOCALE_ID. That token also affects ICU expressions. Angular documents en-US as the default; setting another locale is an application configuration choice, not an automatic consequence of a visitor’s browser language. See Angular’s LOCALE_ID API and locale ID guide.

As an Amazon Associate I earn from qualifying purchases.

Locale identifiers follow Unicode locale identifier conventions based on BCP 47 tags and CLDR. Choose the language and region that match the application’s requirements: en-US and en-CA are distinct locales, and may differ in punctuation, date conventions, number formatting, and grammar.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set an application-wide default

Provide LOCALE_ID in the application’s providers to make a locale the default for Angular’s locale-aware formatting and ICU expressions. For example, in a standalone application’s provider configuration:

import { LOCALE_ID } from '@angular/core';

providers: [
  { provide: LOCALE_ID, useValue: 'fr' }
]

Use the locale ID your application actually targets. Changing the token does not by itself add the locale’s formatting data to the application.

Format values in a template

Use a pipe whose value type matches the output you need. Angular’s locale formatting guide documents these pipes and their locale behavior.

Value Template example What to specify
Date or time {{ today | date }} Choose a format and timezone when defaults are not suitable.
Currency {{ amount | currency:'USD':'symbol':'1.2-2':'en-US' }} Pass the currency code separately from the locale; set display and precision as needed.
Decimal number {{ value | number:'1.0-3':'fr' }} The digit pattern controls integer and fraction digits; the locale controls separators and grouping.
Percentage {{ rate | percent }} Use the locale-aware percent pipe; choose explicit formatting options when required.

The examples show pipe syntax; output punctuation and symbols follow the selected locale and options. For the exact argument definitions, see Angular’s DecimalPipe and CurrencyPipe APIs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Control decimal precision

DecimalPipe accepts digit settings in the form {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}. For example, 1.0-3 requests at least one integer digit, allows no required fraction digits, and permits up to three fraction digits. Supply an explicit locale argument when the value should not rely on the application default.

Keep currency and locale separate

A locale describes formatting conventions; it does not decide what currency an amount represents. Pass the intended currency code, such as USD or CAD, as a separate argument. Currency fraction digits differ by currency, so set digit options when the display must follow a particular application requirement rather than relying on currency defaults. The locale argument on CurrencyPipe can override the application’s LOCALE_ID.

Register locale data for other locales

Angular includes only en-US locale data by default. For another date locale, import its locale data and register it with registerLocaleData before relying on localized date formatting. The registerLocaleData API documents registration, and the DatePipe API notes the default-data limitation.

import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';

registerLocaleData(localeFr);

Register the data corresponding to the locale you intend to use. Setting LOCALE_ID and registering locale data solve different parts of configuration: the former selects a default locale; the latter makes additional locale data available.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Make date output predictable

DatePipe accepts a date value, format, timezone, and locale. If you omit the timezone, Angular uses configured default options or the host system timezone; consequently, the same instant may display with a different calendar date or time in different environments. Supply a timezone when output must be consistent. The DatePipe API describes the parameters and behavior.

DatePipe is pure. If you mutate an existing Date object in place, Angular does not rerun the pipe. Replace it with a new Date object reference when the displayed date changes.

Format values outside templates

In a service or other TypeScript code, use Angular’s standalone functions from @angular/common rather than injecting a pipe class. The available functions are formatDate, formatCurrency, formatNumber, and formatPercent. Choose the function that matches the value and pass the locale and other options required by that call. Angular’s pipes guide recommends these functions for formatting outside templates.

Choose the right configuration

  • Use LOCALE_ID when the application needs one locale as its default across built-in pipes and ICU expressions.
  • Use a per-call locale when a particular output needs a locale different from the application default, where the pipe or function supports that argument.
  • Register locale data when formatting with a locale beyond Angular’s built-in en-US data, especially for dates.
  • Set explicit options for currencies, precision, formats, or timezones whenever defaults could make the output ambiguous or environment-dependent.
  • Use a pipe in a template and a formatting function in code to keep the approach appropriate to the execution context.

For broader application localization beyond formatting values, see Angular’s internationalization guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.