Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
王士厅
2024-05-27 17:08:44 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e474ffc188baf6aa83aba51ab7958ee2a390d63e
e474ffc1
1 parent
b189151f
全域规则-评论数/点赞数亿以上,展示错误,评论数,万以上/亿以上,x.x万/亿,小数点后为0时不应显示
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
3 deletions
sight_harmony/commons/wdKit/src/main/ets/utils/NumberFormatterUtils.ets
sight_harmony/commons/wdKit/src/main/ets/utils/NumberFormatterUtils.ets
View file @
e474ffc
...
...
@@ -8,11 +8,20 @@ export class NumberFormatterUtils {
*/
static formatNumberWithWan(inputNumber: number | String): string {
const num = typeof inputNumber === 'number' ? inputNumber : Number(inputNumber);
if (Number.isNaN(num) || num < 10000) {
if (Number.isNaN(num)) {
return '';
} else if (num < 10000) {
return num.toString();
} else {
} else if (num < 100000000) {
// 处理 1万到1亿之间的数字,使用万作为单位,小数点后为0则不显示
const wanUnit = num / 10000;
return `${wanUnit.toFixed(1)}万`;
const formattedWan = wanUnit.toFixed(1);
return formattedWan.endsWith('.0') ? `${Math.floor(wanUnit)}万` : `${formattedWan}万`;
} else {
// 数字达到1亿及以上时,转换为亿并处理小数点后为0的情况
const yiUnit = num / 100000000;
const formattedYi = yiUnit.toFixed(1);
return formattedYi.endsWith('.0') ? `${formattedYi.slice(0, -2)}亿` : `${formattedYi}亿`;
}
}
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment