do to formatters
This commit is contained in:
12
apps/website/lib/formatters/WinRateFormatter.ts
Normal file
12
apps/website/lib/formatters/WinRateFormatter.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export class WinRateFormatter {
|
||||
static calculate(racesCompleted: number, wins: number): string {
|
||||
if (racesCompleted === 0) return '0.0';
|
||||
const rate = (wins / racesCompleted) * 100;
|
||||
return rate.toFixed(1);
|
||||
}
|
||||
|
||||
static format(rate: number | null | undefined): string {
|
||||
if (rate === null || rate === undefined) return '0.0%';
|
||||
return `${rate.toFixed(1)}%`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user