MCPcopy Index your code
hub / github.com/angular/angular / formatCurrency

Function formatCurrency

packages/common/src/i18n/format_number.ts:182–214  ·  view source on GitHub ↗
(
  value: number,
  locale: string,
  currency: string,
  currencyCode?: string,
  digitsInfo?: string,
)

Source from the content-addressed store, hash-verified

180 * @publicApi
181 */
182export function formatCurrency(
183 value: number,
184 locale: string,
185 currency: string,
186 currencyCode?: string,
187 digitsInfo?: string,
188): string {
189 const format = getLocaleNumberFormat(locale, NumberFormatStyle.Currency);
190 const pattern = parseNumberFormat(format, getLocaleNumberSymbol(locale, NumberSymbol.MinusSign));
191
192 pattern.minFrac = getNumberOfCurrencyDigits(currencyCode!);
193 pattern.maxFrac = pattern.minFrac;
194
195 const res = formatNumberToLocaleString(
196 value,
197 pattern,
198 locale,
199 NumberSymbol.CurrencyGroup,
200 NumberSymbol.CurrencyDecimal,
201 digitsInfo,
202 );
203 return (
204 res
205 .replace(CURRENCY_CHAR, currency)
206 // if we have 2 time the currency character, the second one is ignored
207 .replace(CURRENCY_CHAR, '')
208 // If there is a spacing between currency character and the value and
209 // the currency character is suppressed by passing an empty string, the
210 // spacing character would remain as part of the string. Then we
211 // should remove it.
212 .trim()
213 );
214}
215
216/**
217 * @ngModule CommonModule

Callers 2

transformMethod · 0.90

Calls 6

getLocaleNumberFormatFunction · 0.90
getLocaleNumberSymbolFunction · 0.90
parseNumberFormatFunction · 0.85
replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…