refactor(HeroBoxComp): 替换手动格式化逻辑为NumberFormatter

统一大数值展示格式,使用千分位缩写避免溢出标签,同时保留小数位数的原有逻辑
This commit is contained in:
pan
2026-08-06 11:13:48 +08:00
parent 7436944752
commit 407973655a

View File

@@ -21,7 +21,7 @@ import { GameEvent } from "../common/config/GameEvent";
import { HeroInfo } from "../common/config/heroSet";
import { HeroAttrsComp } from "../hero/HeroAttrsComp";
import { Hero } from "../hero/Hero";
import { FacSet, FightSet, getLvColor } from "../common/config/GameSet";
import { FacSet, FightSet, getLvColor, NumberFormatter } from "../common/config/GameSet";
import { buildSkillDesc, ISkillDescSource } from "../common/config/HeroSkillDesc";
import { MissionEconomy } from "./MissionEconomy";
import { UIID } from "../common/config/GameUIConfig";
@@ -592,7 +592,8 @@ export class HeroBoxComp extends CCComp {
* @param decimals 保留小数位数(默认 0取整
*/
private setStatRow(allLabel: Label | null, plusLabel: Label | null, total: number, bonus: number, suffix: string = "", decimals: number = 0) {
const fmt = (v: number) => decimals > 0 ? v.toFixed(decimals) : `${Math.floor(v)}`;
// 整数数值统一走 NumberFormatter 千分位缩写(如 12.3k),避免大数值溢出标签
const fmt = (v: number) => decimals > 0 ? v.toFixed(decimals) : NumberFormatter.formatNumber(Math.floor(v));
if (allLabel && allLabel.isValid) {
allLabel.string = `${fmt(total)}${suffix}`;
}