fix: correct percentage rounding
This commit is contained in:
+11
-2
@@ -106,6 +106,16 @@ function buildBaseFromEquip(
|
|||||||
return base;
|
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(
|
function formatValue(
|
||||||
key: string,
|
key: string,
|
||||||
value: number | undefined,
|
value: number | undefined,
|
||||||
@@ -113,8 +123,7 @@ function formatValue(
|
|||||||
): string {
|
): string {
|
||||||
if (value == null) return "0";
|
if (value == null) return "0";
|
||||||
const name = String(key);
|
const name = String(key);
|
||||||
if (percentageList.includes(name))
|
if (percentageList.includes(name)) return `${roundPercent(value)}%`;
|
||||||
return `${(Number(value) * 100).toFixed(1)}%`;
|
|
||||||
// if (/HP|ATTACK|DEFENSE|CUR_ATTACK|MAX_HP|CUR_DEFENSE/.test(name))
|
// if (/HP|ATTACK|DEFENSE|CUR_ATTACK|MAX_HP|CUR_DEFENSE/.test(name))
|
||||||
// return Math.round(Number(value)).toString();
|
// return Math.round(Number(value)).toString();
|
||||||
return Math.round(Number(value)).toLocaleString();
|
return Math.round(Number(value)).toLocaleString();
|
||||||
|
|||||||
Reference in New Issue
Block a user