formatPercent()function

formatPercent(numerator: number, denumerator?: number, options?: PercentFormatOptions): string
ParamType
numeratornumber
Number representing the amount of progress (e.g. 50). required
denumeratornumber
The number representing the whole amount (defaults to 100).
optionsPercentFormatOptions
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 0 zero to 1 range. This uses getPercent() which works on 0 to 100 for convenience.

Examples

formatPercent(50) // "50%"