formatPercent()function
formatPercent(numerator: number, denumerator?: number, options?: PercentFormatOptions): string
| Param | Type | |
|---|---|---|
numerator | number | Number representing the amount of progress (e.g. 50). required |
denumerator | number | The number representing the whole amount (defaults to 100). |
options | PercentFormatOptions | Formatting options passed through to Intl.NumberFormat. |
| Return | |
|---|---|
string | Locale-formatted percentage string. |
Format a percentage (combines getPercent() and formatUnit() for convenience).
- Defaults to showing no decimal places.
- Defaults to rounding closer to zero (so that 99.99% is shown as 99%).
- Javascript's built-in percent formatting works on the
0zero to1range. This usesgetPercent()which works on0to100for convenience.
Examples
formatPercent(50) // "50%"