( value: number, locale: string, currency: string, currencyCode?: string, digitsInfo?: string, )
| 180 | * @publicApi |
| 181 | */ |
| 182 | export 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 |
no test coverage detected
searching dependent graphs…