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