mirror of
https://github.com/blossom-editor/blossom
synced 2024-11-17 22:48:03 +08:00
数字格式化工具类修改
This commit is contained in:
parent
6638563cac
commit
957cd6bc6b
@ -233,11 +233,15 @@ export const formatFileSize = (size: number): string => {
|
|||||||
/**
|
/**
|
||||||
* 将数字转为千分位的字符串
|
* 将数字转为千分位的字符串
|
||||||
* @param param
|
* @param param
|
||||||
* @returns
|
* @returns 返回字符串
|
||||||
*/
|
*/
|
||||||
export const formartNumber = (param: number): string => {
|
export const formartNumber = (param: number): string => {
|
||||||
let num: string = (param || 0).toString(),
|
let num: string = (param || 0).toString()
|
||||||
result: string = ''
|
let result: string = ''
|
||||||
|
let isNegative = param < 0
|
||||||
|
if (isNegative) {
|
||||||
|
num = num.substring(1)
|
||||||
|
}
|
||||||
while (num.length > 3) {
|
while (num.length > 3) {
|
||||||
result = ',' + num.slice(-3) + result
|
result = ',' + num.slice(-3) + result
|
||||||
num = num.slice(0, num.length - 3)
|
num = num.slice(0, num.length - 3)
|
||||||
@ -245,6 +249,9 @@ export const formartNumber = (param: number): string => {
|
|||||||
if (num) {
|
if (num) {
|
||||||
result = num + result
|
result = num + result
|
||||||
}
|
}
|
||||||
|
if (isNegative) {
|
||||||
|
return '-' + result
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user