website refactor
This commit is contained in:
25
apps/website/lib/display-objects/PercentDisplay.ts
Normal file
25
apps/website/lib/display-objects/PercentDisplay.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* PercentDisplay
|
||||
*
|
||||
* Deterministic formatting for percentages.
|
||||
*/
|
||||
|
||||
export class PercentDisplay {
|
||||
/**
|
||||
* Formats a decimal value as a percentage string.
|
||||
* Example: 0.1234 -> "12.3%"
|
||||
*/
|
||||
static format(value: number | null | undefined): string {
|
||||
if (value === null || value === undefined) return '0.0%';
|
||||
return `${(value * 100).toFixed(1)}%`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a whole number as a percentage string.
|
||||
* Example: 85 -> "85%"
|
||||
*/
|
||||
static formatWhole(value: number | null | undefined): string {
|
||||
if (value === null || value === undefined) return '0%';
|
||||
return `${Math.round(value)}%`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user