October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Formatting Data with Pipes in Angular

Format Angular template values with the right built-in pipe, and control locale, date timezone, and numeric precision for predictable output.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Angular’s built-in date, currency, number, and percent pipes to format values directly in a template. Their output follows locale rules, so choose the right pipe and configure locale, date timezone, and numeric precision where the displayed result needs to be predictable.

Choose a pipe for the value you are displaying

Pipe Use it for What it controls
DatePipe (date) Dates and times Date format, timezone, and locale
CurrencyPipe (currency) Monetary amounts Currency code, display, digits, and locale
DecimalPipe (number) General numeric quantities Grouping and fractional digits
PercentPipe (percent) Ratios displayed as percentages Fractional digits and locale

These are among the transformation pipes Angular provides in @angular/common. See Angular’s Pipes guide and locale formatting guide.

As an Amazon Associate I earn from qualifying purchases.

Use pipes in a template

Import the pipe you need from @angular/common into the component that uses it. Then place the pipe after the value in a template expression:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
{{ amount | currency }}
{{ purchasedOn | date }}

Pass options after the pipe name using colons. Multiple arguments use additional colons; for example, a date expression can provide a format and then a timezone. Use parentheses when an expression is complex enough that it is unclear which value the pipe receives.

Set locale deliberately

Locale changes visible formatting, including digit grouping and decimal separators. These built-in formatting pipes use Angular’s LOCALE_ID by default; the token defaults to en-US. Some pipes also accept an explicit locale argument, which overrides the default for that formatting operation. The LOCALE_ID API documents the token.

Angular includes only en-US locale data by default. If an application needs another locale’s conventions, import that locale data as described in the locale formatting guide. Setting a locale identifier without the required data does not by itself supply that locale’s formatting data.

Format dates with DatePipe

DatePipe accepts a date string, a Date object, or a number representing milliseconds since the UTC epoch. Its template argument order is format, timezone, then locale:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
{{ value_expression | date:format:timezone:locale }}

Choose a format and timezone

The format can be a predefined option or a custom format string. If omitted, Angular checks DATE_PIPE_DEFAULT_OPTIONS; if that token is not configured, the format is mediumDate. The timezone follows a similar default: Angular checks the default-options token, then uses the end user’s local system timezone if no default is configured and no timezone is passed.

If the display must be consistent across users, specify or configure the intended timezone rather than relying on each user’s system setting. The DatePipe API documents accepted values, defaults, and arguments.

Account for pure-pipe change detection

DatePipe is pure: Angular reruns it when a primitive input changes or an object reference changes. Mutating an existing Date object in place does not trigger a new formatted result. Create and assign a new Date object when the represented date changes.

Control numeric precision

DecimalPipe accepts digitsInfo in this form:

{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}

Its defaults are one minimum integer digit, zero minimum fractional digits, and three maximum fractional digits. Locale controls grouping and separator characters. When the requested precision limits the output, the value is rounded: Angular’s API example formats 3.6 with zero fractional digits as 4. See the DecimalPipe API.

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

Currency and percentage output

CurrencyPipe accepts a currency code, display option, digits, and locale. PercentPipe accepts optional digits and locale arguments. Because locale and currency choices affect what readers see, specify the currency code and locale when the intended display should not depend on application defaults. Refer to Angular’s CurrencyPipe API and PercentPipe API for the argument details.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Format values outside templates

For formatting in services or other non-template code, use Angular’s standalone formatDate, formatCurrency, formatNumber, and formatPercent functions. Angular recommends these functions instead of injecting pipe classes into a service. The Pipes guide covers both template pipes and the formatting functions.

When to write a custom pipe

Use a custom pipe when a transformation belongs in template expressions and should be reusable. Angular’s documented approach is to add @Pipe and implement PipeTransform; additional pipe parameters are passed as arguments to transform.

Keep custom pipes pure unless the transformation truly requires checking for changes beyond changed values or references. Angular cautions: “Avoid creating impure pipes unless absolutely necessary, as they can incur a significant performance penalty if used without care.” The official Pipes guide explains the distinction.

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.