| 98 | let numberFormatterForConsistentDecimals: Intl.NumberFormat | null = null |
| 99 | let numberFormatterForInconsistentDecimals: Intl.NumberFormat | null = null |
| 100 | const getNumberFormatter = ( |
| 101 | useConsistentDecimals: boolean, |
| 102 | ): Intl.NumberFormat => { |
| 103 | if (useConsistentDecimals) { |
| 104 | if (!numberFormatterForConsistentDecimals) { |
| 105 | numberFormatterForConsistentDecimals = new Intl.NumberFormat('en-US', { |
| 106 | notation: 'compact', |
| 107 | maximumFractionDigits: 1, |
| 108 | minimumFractionDigits: 1, |
| 109 | }) |
| 110 | } |
| 111 | return numberFormatterForConsistentDecimals |
| 112 | } else { |
| 113 | if (!numberFormatterForInconsistentDecimals) { |
| 114 | numberFormatterForInconsistentDecimals = new Intl.NumberFormat('en-US', { |
| 115 | notation: 'compact', |
| 116 | maximumFractionDigits: 1, |
| 117 | minimumFractionDigits: 0, |
| 118 | }) |
| 119 | } |
| 120 | return numberFormatterForInconsistentDecimals |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | export function formatNumber(number: number): string { |
| 125 | // Only use minimumFractionDigits for numbers that will be shown in compact notation |