Normalizes a ratio into a percentage value rounded to a fixed precision.
The value is kept on a 0–1 scale (i.e. 0.2525 represents 25.25%) so it stays composable with other math; use toPercentString for display.
0.2525
A ratio, typically between 0 and 1.
Decimal places to keep. Defaults to 4.
4
The rounded ratio, or 0 when the input is not finite.
0
toPercentage(1 / 3); // 0.3333 Copy
toPercentage(1 / 3); // 0.3333
Normalizes a ratio into a percentage value rounded to a fixed precision.
The value is kept on a 0–1 scale (i.e.
0.2525represents 25.25%) so it stays composable with other math; use toPercentString for display.