@@ -10,7 +10,7 @@ export function formatByDecimalPlaces(value: number | string, decimalPlaces: num
1010 return value ;
1111 }
1212 let strValue = ( + value ) . toFixed ( decimalPlaces ) ;
13- if ( ! / ^ [ 0 - 9 . ] + $ / g. test ( strValue ) ) {
13+ if ( ! / ^ - ? [ 0 - 9 . ] + $ / g. test ( strValue ) ) {
1414 return '0' ;
1515 }
1616 while ( strValue . includes ( '.' ) && ( strValue . endsWith ( '.' ) || strValue . endsWith ( '0' ) ) ) {
@@ -72,17 +72,20 @@ export const getFormattedValue = (value: number | string, remainZero?: boolean)
7272 if ( ! isFinite ( + value ) ) {
7373 return value ;
7474 }
75+
76+ const absNumericValue = Math . abs ( + value ) ;
77+
7578 const unit =
76- + value >= 100000000
79+ absNumericValue >= 100000000
7780 ? NumericUnit . OneHundredMillion
78- : + value >= 10000
81+ : absNumericValue >= 10000
7982 ? NumericUnit . TenThousand
8083 : NumericUnit . None ;
8184
8285 let formattedValue = formatByUnit ( value , unit ) ;
8386 formattedValue = formatByDecimalPlaces (
8487 formattedValue ,
85- unit === NumericUnit . OneHundredMillion ? 2 : + value < 1 ? 3 : 1
88+ unit === NumericUnit . OneHundredMillion ? 2 : absNumericValue < 1 ? 3 : 1
8689 ) ;
8790 formattedValue = formatByThousandSeperator ( formattedValue ) ;
8891 if ( ( typeof formattedValue === 'number' && isNaN ( formattedValue ) ) || + formattedValue === 0 ) {
@@ -93,7 +96,7 @@ export const getFormattedValue = (value: number | string, remainZero?: boolean)
9396
9497export const formatNumberWithCN = ( num : number ) => {
9598 if ( isNaN ( num ) ) return '-' ;
96- if ( num >= 10000 ) {
99+ if ( Math . abs ( + num ) >= 10000 ) {
97100 return ( num / 10000 ) . toFixed ( 1 ) + '万' ;
98101 } else {
99102 return formatByDecimalPlaces ( num , 2 ) ;
0 commit comments