fix: correct percentage rounding
This commit is contained in:
+11
-2
@@ -106,6 +106,16 @@ function buildBaseFromEquip(
|
||||
return base;
|
||||
}
|
||||
|
||||
// round to 2 precision first, then 1(probably how enka does it)
|
||||
// so that 59.04999 becomes 59.1 instead of 59.0
|
||||
function roundPercent(value: number): number {
|
||||
const percent = value * 100;
|
||||
|
||||
const fixed2 = Math.round(percent * 100) / 100;
|
||||
|
||||
return Math.round(fixed2 * 10) / 10;
|
||||
}
|
||||
|
||||
function formatValue(
|
||||
key: string,
|
||||
value: number | undefined,
|
||||
@@ -113,8 +123,7 @@ function formatValue(
|
||||
): string {
|
||||
if (value == null) return "0";
|
||||
const name = String(key);
|
||||
if (percentageList.includes(name))
|
||||
return `${(Number(value) * 100).toFixed(1)}%`;
|
||||
if (percentageList.includes(name)) return `${roundPercent(value)}%`;
|
||||
// if (/HP|ATTACK|DEFENSE|CUR_ATTACK|MAX_HP|CUR_DEFENSE/.test(name))
|
||||
// return Math.round(Number(value)).toString();
|
||||
return Math.round(Number(value)).toLocaleString();
|
||||
|
||||
Reference in New Issue
Block a user