mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 15:26:15 +08:00
fix: show average showing decimals even if decimals are disabled
This commit is contained in:
parent
8852c592f7
commit
5a2250c3f5
|
@ -147,7 +147,8 @@ export async function update(): Promise<void> {
|
|||
if (Auth?.currentUser && avgWPM > 0) {
|
||||
const avgWPMText = ["speed", "both"].includes(Config.showAverage)
|
||||
? getTypingSpeedUnit(Config.typingSpeedUnit).convertWithUnitSuffix(
|
||||
avgWPM
|
||||
avgWPM,
|
||||
Config.alwaysShowDecimalPlaces
|
||||
)
|
||||
: "";
|
||||
|
||||
|
|
|
@ -259,8 +259,11 @@ function updateWpmAndAcc(): void {
|
|||
);
|
||||
} else {
|
||||
//not showing decimal places
|
||||
let wpmHover = typingSpeedUnit.convertWithUnitSuffix(result.wpm);
|
||||
let rawWpmHover = typingSpeedUnit.convertWithUnitSuffix(result.rawWpm);
|
||||
let wpmHover = typingSpeedUnit.convertWithUnitSuffix(result.wpm, true);
|
||||
let rawWpmHover = typingSpeedUnit.convertWithUnitSuffix(
|
||||
result.rawWpm,
|
||||
true
|
||||
);
|
||||
if (Config.typingSpeedUnit != "wpm") {
|
||||
wpmHover += " (" + result.wpm.toFixed(2) + " wpm)";
|
||||
rawWpmHover += " (" + result.rawWpm.toFixed(2) + " wpm)";
|
||||
|
|
2
frontend/src/ts/types/types.d.ts
vendored
2
frontend/src/ts/types/types.d.ts
vendored
|
@ -908,7 +908,7 @@ declare namespace MonkeyTypes {
|
|||
interface TypingSpeedUnitSettings {
|
||||
fromWpm: (number) => number;
|
||||
toWpm: (number) => number;
|
||||
convertWithUnitSuffix: (number) => string;
|
||||
convertWithUnitSuffix: (number, boolean) => string;
|
||||
fullUnitString: string;
|
||||
histogramDataBucketSize: number;
|
||||
historyStepSize: number;
|
||||
|
|
|
@ -29,8 +29,12 @@ class Unit implements MonkeyTypes.TypingSpeedUnitSettings {
|
|||
return val / this.convertFactor;
|
||||
}
|
||||
|
||||
convertWithUnitSuffix(wpm: number): string {
|
||||
return roundTo2(this.fromWpm(wpm)).toFixed(2) + " " + this.unit;
|
||||
convertWithUnitSuffix(wpm: number, withDecimals: boolean): string {
|
||||
if (withDecimals) {
|
||||
return roundTo2(this.fromWpm(wpm)).toFixed(2) + " " + this.unit;
|
||||
} else {
|
||||
return Math.round(this.fromWpm(wpm)) + " " + this.unit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue