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:09:47 +0800
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
bbf30c5f98b44c0cac092922f929ce60ceec8923
bbf30c5f
2 parents
6252ef15
4ee23b8a
Merge remote-tracking branch 'origin/main'
Show 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 @
bbf30c5
...
...
@@ -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