12 lines
380 B
TypeScript
12 lines
380 B
TypeScript
export class WinRateDisplay {
|
|
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)}%`;
|
|
}
|
|
} |