fix: show average showing decimals even if decimals are disabled

This commit is contained in:
Miodec 2023-10-11 14:39:36 +01:00
parent 8852c592f7
commit 5a2250c3f5
4 changed files with 14 additions and 6 deletions

View file

@ -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
)
: "";

View file

@ -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)";

View file

@ -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;

View file

@ -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;
}
}
}