You've already forked decomp.dev
mirror of
https://github.com/encounter/decomp.dev.git
synced 2026-07-10 03:18:48 -07:00
13 lines
429 B
TypeScript
13 lines
429 B
TypeScript
export function clamp(value: number, min: number, max: number) {
|
|
return Math.min(Math.max(value, min), max);
|
|
}
|
|
|
|
// Formats a progress percentage as a string, and prevents partial matches from being rounded to 0.00% or 100.00%.
|
|
export function formatPercent(value: number) {
|
|
let clamped = value;
|
|
if (clamped !== 0.0 && clamped !== 100.0) {
|
|
clamped = clamp(clamped, 0.01, 99.99);
|
|
}
|
|
return `${clamped.toFixed(2)}%`;
|
|
}
|