设置卡片数据占满时以K方式显示数据

This commit is contained in:
Alex Yang
2025-11-27 00:40:50 +08:00
parent 91241d08da
commit f89522cb88
7 changed files with 327 additions and 205 deletions

View File

@@ -263,12 +263,25 @@ function addGlowEffect() {
// 格式化数字
function formatNumber(num) {
// 显示完整数字的最大长度阈值
const MAX_FULL_LENGTH = 5;
// 先获取完整数字字符串
const fullNumStr = num.toString();
// 如果数字长度小于等于阈值,直接返回完整数字
if (fullNumStr.length <= MAX_FULL_LENGTH) {
return fullNumStr;
}
// 否则使用缩写格式
if (num >= 1000000) {
return (num / 1000000).toFixed(1) + 'M';
} else if (num >= 1000) {
return (num / 1000).toFixed(1) + 'K';
}
return num.toString();
return fullNumStr;
}
// 在DOM加载完成后初始化