Don't round partially-matched percentages to 0.00% or 100.00% (#8)

* Don't round percentages to 0.00% or 100.00%

* Remove dead code
This commit is contained in:
LagoLunatic
2025-07-23 18:23:00 -06:00
committed by GitHub
parent 39fa6ad3bb
commit baf4d5d2bc
10 changed files with 58 additions and 48 deletions
+11
View File
@@ -0,0 +1,11 @@
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) {
if (value !== 0.0 && value !== 100.0) {
value = clamp(value, 0.01, 99.99);
}
return `${value.toFixed(2)}%`;
}