feat:增加AList博客
This commit is contained in:
@@ -18,6 +18,30 @@ export const countWord = (data: string)=> {
|
||||
return count
|
||||
}
|
||||
|
||||
export const formatNumberUnit = (num: number, fixed = 1) => {
|
||||
if (typeof num !== 'number') {
|
||||
num = parseFloat(num);
|
||||
}
|
||||
|
||||
if (isNaN(num)) return '0';
|
||||
|
||||
const absNum = Math.abs(num);
|
||||
let result;
|
||||
|
||||
if (absNum >= 100000000) {
|
||||
// 亿
|
||||
result = (num / 100000000).toFixed(fixed) + '亿';
|
||||
} else if (absNum >= 10000) {
|
||||
// 万
|
||||
result = (num / 10000).toFixed(fixed) + '万';
|
||||
} else {
|
||||
result = num.toFixed(0);
|
||||
}
|
||||
|
||||
// 移除多余的 .0
|
||||
return result.replace(/\.0+($|亿|万)/, '$1');
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为移动端
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user