Function
formatNumber
(
config: {
locale: string
formats: CustomFormats
onError: OnErrorFn
},
getNumberFormat: Formatters['getNumberFormat'],
value: Parameters<IntlFormatters['formatNumber']>[0],
options: Parameters<IntlFormatters['formatNumber']>[1] = {}
)
Source from the content-addressed store, hash-verified
| 66 | } |
| 67 | |
| 68 | export function formatNumber( |
| 69 | config: { |
| 70 | locale: string |
| 71 | |
| 72 | formats: CustomFormats |
| 73 | onError: OnErrorFn |
| 74 | }, |
| 75 | getNumberFormat: Formatters['getNumberFormat'], |
| 76 | value: Parameters<IntlFormatters['formatNumber']>[0], |
| 77 | options: Parameters<IntlFormatters['formatNumber']>[1] = {} |
| 78 | ): string { |
| 79 | try { |
| 80 | return getFormatter(config, getNumberFormat, options).format(value) |
| 81 | } catch (e) { |
| 82 | config.onError( |
| 83 | new IntlFormatError('Error formatting number.', config.locale, e) |
| 84 | ) |
| 85 | } |
| 86 | |
| 87 | return String(value) |
| 88 | } |
| 89 | |
| 90 | export function formatNumberToParts( |
| 91 | config: { |