66 formatFloatingPointValue ,
77} from '@/libs/utils/number-formatter' ;
88import { useCurrencyStore } from '../views/settings/store' ;
9+
910export const replaceWithEllipsis = (
1011 value : string ,
1112 keepLeft : number ,
@@ -35,8 +36,29 @@ export const parseCurrency = (value: string | number): string => {
3536 amount . isNaN ( ) || amount . isZero ( )
3637 ? 0
3738 : amount . times ( exchangeRate ) . toNumber ( ) ;
39+
3840 const notation = BigNumber ( finalValue ) . gt ( 999999 ) ? 'compact' : 'standard' ;
39- return `${ amount . lt ( 0.0000001 ) && amount . gt ( 0 ) ? '< ' : '' } ${ new Intl . NumberFormat ( locale , { style : 'currency' , currency : currency , notation } ) . format ( finalValue ) } ` ;
41+
42+ let minimumFractionDigits = 2 ;
43+ let maximumFractionDigits = 2 ;
44+
45+ if ( finalValue > 0 && finalValue < 0.01 ) {
46+ minimumFractionDigits = 2 ;
47+ maximumFractionDigits = 8 ;
48+ } else if ( finalValue >= 0.01 && finalValue < 1 ) {
49+ minimumFractionDigits = 2 ;
50+ maximumFractionDigits = 4 ;
51+ }
52+
53+ const formatted = new Intl . NumberFormat ( locale , {
54+ style : 'currency' ,
55+ currency : currency ,
56+ notation,
57+ minimumFractionDigits,
58+ maximumFractionDigits,
59+ } ) . format ( finalValue ) ;
60+
61+ return `${ amount . lt ( 0.0000001 ) && amount . gt ( 0 ) ? '< ' : '' } ${ formatted } ` ;
4062} ;
4163
4264export const truncate = ( value : string , length : number ) : string => {
@@ -60,4 +82,5 @@ export const formatDuration = (
6082
6183 return `${ m . padStart ( 2 , '0' ) } :${ s . padStart ( 2 , '0' ) } ` ;
6284} ;
85+
6386export { formatFiatValue , formatFloatingPointValue } ;
0 commit comments