@molecule/app-currency-display-angular
Feature · currency-display · App (browser) · v1.1.1 · Apache-2.0
Currency amount formatting + CurrencyDisplay with optional original price + savings badge
npm install @molecule/app-currency-display-angularHow it works
@molecule/app-currency-display-angular is a ready-made currency-display feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
import { Component } from '@angular/core'
import { CurrencyDisplay, formatCurrency } from '@molecule/app-currency-display-angular'
@Component({
selector: 'app-price',
standalone: true,
imports: [CurrencyDisplay],
template: `
<!-- Basic amount -->
<span mol-currency-display [amount]="49.99" currency="USD" size="lg"></span>
<!-- With original price and savings chip -->
<span mol-currency-display [amount]="29.99" [originalAmount]="49.99" showSavings></span>
<!-- Compact notation: "$29.99K" -->
<span mol-currency-display [amount]="29990" compact size="xl"></span>
`,
})
export class Price {
// Plain string utility
label = formatCurrency(1234.56, 'EUR', 'de-DE') // "1.234,56 €"
}Works with: @molecule/app-angular, @molecule/app-ui, @molecule/app-ui-angular
Reference
Angular currency display and formatting utilities — the counterpart of
@molecule/app-currency-display-react, with the same props and the same DOM
for the same input.
Exports:
formatCurrency(amount, currency?, locale?)— plain string viaIntl.NumberFormat.formatCurrencyCompact(amount, currency?, locale?)— compact notation ($12.3K).CurrencyDisplay— rendered amount with optional strikethrough original price + savings chip.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
import { Component } from '@angular/core'
import { CurrencyDisplay, formatCurrency } from '@molecule/app-currency-display-angular'
@Component({
selector: 'app-price',
standalone: true,
imports: [CurrencyDisplay],
template: `
<!-- Basic amount -->
<span mol-currency-display [amount]="49.99" currency="USD" size="lg"></span>
<!-- With original price and savings chip -->
<span mol-currency-display [amount]="29.99" [originalAmount]="49.99" showSavings></span>
<!-- Compact notation: "$29.99K" -->
<span mol-currency-display [amount]="29990" compact size="xl"></span>
`,
})
export class Price {
// Plain string utility
label = formatCurrency(1234.56, 'EUR', 'de-DE') // "1.234,56 €"
}
Type
feature
Installation
npm install @molecule/app-currency-display-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular
API
Interfaces
CurrencyDisplayProps
Props for CurrencyDisplay.
interface CurrencyDisplayProps {
/** Current amount in major units. */
amount: number
/** Optional original amount — rendered strikethrough to show a discount. */
originalAmount?: number
/** ISO 4217 currency code. */
currency?: string
/** Locale override. */
locale?: string
/** Display size. */
size?: 'sm' | 'md' | 'lg' | 'xl'
/** Compact notation (`$12.3K`) instead of full. */
compact?: boolean
/** Show a savings chip when `originalAmount > amount`. */
showSavings?: boolean
/** Custom savings label renderer. */
savingsLabel?: (saved: number, pct: number) => string
/** Extra classes. */
className?: string
}
Classes
CurrencyDisplay
CurrencyDisplay component: an amount, an optional strikethrough original price and a "saved X%" chip.
The host IS React's root <span> (span[mol-currency-display]), matching
React's DOM exactly. Uses Intl.NumberFormat under the hood; the ClassMap
tokens come from @molecule/app-ui, as in React.
@Component({
selector: 'span[mol-currency-display]',
standalone: true,
inputs: [
'amount',
'originalAmount',
'currency',
'locale',
'size',
'compact',
'showSavings',
'savingsLabel',
'className',
],
host: {
'[class]': 'classes()',
},
template: `
<span [class]="amountClass()">{{ amountText() }}</span>
@if (discount(); as d) {
<span [class]="originalClass()" style="text-decoration: line-through">{{
originalText(d)
}}</span>
@if (showSavingsOn()) {
<span [class]="savingsClass()">{{ savingsText(d) }}</span>
}
}
`,
})
export class CurrencyDisplay implements CurrencyDisplayProps {
/** Current amount in major units. */
amount: number = 0
/** Optional original amount — rendered strikethrough to show a discount. */
originalAmount?: number
/** ISO 4217 currency code (defaults to `'USD'` at read time). */
currency?: string
/** Locale override. */
locale?: string
/** Display size (defaults to `'md'` at read time). */
size?: CurrencyDisplayProps['size']
/** Compact notation (`$12.3K`) instead of full. */
compact?: boolean
/** Show a savings chip when `originalAmount > amount` (defaults to `true`). */
showSavings?: boolean
/** Custom savings label renderer. */
savingsLabel?: (saved: number, pct: number) => string
/** Extra classes on the root span. */
className?: string
/**
* The current class map.
* @returns The UIClassMap.
*/
cm(): UIClassMap {
return getClassMap()
}
/**
* The root span's class list.
* @returns The class string.
*/
classes(): string {
return this.cm().cn(this.cm().flex({ align: 'baseline', gap: 'sm' }), this.className)
}
/**
* The amount span's class list (text size for `size`, bold weight).
* @returns The class string.
*/
amountClass(): string {
return this.cm().cn(this.cm().textSize(this.sizeToken()), this.cm().fontWeight('bold'))
}
/**
* The strikethrough original price's class list.
* @returns The class string.
*/
originalClass(): string {
return this.cm().cn(this.cm().textSize('sm'))
}
/**
* The savings chip's class list.
* @returns The class string.
*/
savingsClass(): string {
return this.cm().cn(this.cm().textSize('xs'), this.cm().fontWeight('semibold'))
}
/**
* The text-size token for the `size` input (React's default is `'md'`).
* @returns The ClassMap text-size token.
*/
sizeToken(): TextScale {
return SIZE_CLASS[this.size ?? 'md']
}
/**
* The formatter for the current `compact` input.
* @returns `formatCurrencyCompact` when compact, else `formatCurrency`.
*/
formatter(): typeof formatCurrency {
return this.compact ? formatCurrencyCompact : formatCurrency
}
/**
* The formatted current amount.
* @returns The formatted amount string.
*/
amountText(): string {
return this.formatter()(this.amount, this.currency ?? 'USD', this.locale)
}
/**
* The formatted original price, when there is a discount.
* @param discount - The rendered discount.
* @returns The formatted original amount string.
*/
originalText(discount: Discount): string {
return this.formatter()(discount.original, this.currency ?? 'USD', this.locale)
}
/**
* The savings chip's text: the custom label when given, else `−X%`.
* @param discount - The rendered discount.
* @returns The chip text.
*/
savingsText(discount: Discount): string {
return this.savingsLabel ? this.savingsLabel(discount.saved, discount.pct) : `−${discount.pct}%`
}
/**
* Whether the savings chip renders (React's `showSavings` default is `true`).
* @returns True when the chip is shown.
*/
showSavingsOn(): boolean {
return this.showSavings ?? true
}
/**
* The discount to render, when the original amount is above the current one
* (React's condition: `originalAmount !== undefined && originalAmount > amount`).
* @returns The discount, or undefined when there is none.
*/
discount(): Discount | undefined {
const original = this.originalAmount
if (original === undefined || original <= this.amount) return undefined
const saved = original - this.amount
return {
original,
saved,
pct: original > 0 ? Math.round((saved / original) * 100) : 0,
}
}
}
Functions
formatCurrency(amount, currency, locale)
Formats a numeric amount as currency using Intl.NumberFormat.
function formatCurrency(amount: number, currency?: string, locale?: string): string
amount— Amount in major units (e.g. dollars, not cents). Passamount / 100if your stored value is in cents.currency— ISO 4217 currency code. Defaults to"USD".locale— BCP 47 locale tag. Defaults to the runtime default (undefined).
Returns: Formatted currency string.
formatCurrencyCompact(amount, currency, locale)
Formats a numeric amount as currency in a compact form (e.g. "$12.3K").
Uses Intl.NumberFormat with notation: 'compact' when supported.
function formatCurrencyCompact(amount: number, currency?: string, locale?: string): string
amount— Amount in major units.currency— ISO 4217 currency code. Defaults to"USD".locale— BCP 47 locale tag. Defaults to the runtime default (undefined).
Returns: Formatted compact currency string.
Injection Notes
Requirements
Peer dependencies:
@angular/common^22.0.0@angular/core^22.0.0@angular/platform-browser^22.0.0@molecule/app-angular^3.5.0 || ^4.0.0@molecule/app-ui^1.0.1@molecule/app-ui-angular^1.1.0
Runtime Dependencies
@angular/common@angular/core@angular/platform-browser@molecule/app-angular@molecule/app-ui@molecule/app-ui-angular
Amounts are in MAJOR units (dollars, not cents) — divide stored cents by
100 first. showSavings defaults to true, so a savings chip appears
whenever originalAmount > amount; pass [showSavings]="false" for plain
was/now price display. Formatting is Intl.NumberFormat (locale-aware,
no i18n keys needed); [savingsLabel] (a (saved, pct) => string function)
lets you localize the chip text.