@@ -5,10 +5,7 @@ import CurrencyMap from './CurrencyMap';
55function NumberFormatter ( value , { locale = 'en-US' , decPlaces = 2 , style = '' , currency = 'USD' } = { } ) : string {
66 const currentLocale : string | undefined = getLocale ( locale ) ;
77 if ( value !== null && value !== undefined ) {
8- return Number ( value ) . toLocaleString ( currentLocale , {
9- minimumFractionDigits : decPlaces ,
10- maximumFractionDigits : decPlaces
11- } ) ;
8+ return Number ( value ) . toLocaleString ( currentLocale , { minimumFractionDigits : decPlaces , maximumFractionDigits : decPlaces } ) ;
129 }
1310 return value ;
1411}
@@ -20,14 +17,16 @@ function CurrencyFormatter(
2017 const currentLocale : string | undefined = getLocale ( locale ) ;
2118 let formattedValue : string = value ;
2219 if ( value !== null && value !== undefined && value !== '' ) {
23- formattedValue = NumberFormatter ( value , {
24- locale : currentLocale ,
25- decPlaces,
26- style,
27- currency
28- } ) ;
20+ formattedValue = NumberFormatter ( value , { locale : currentLocale , decPlaces, style, currency } ) ;
2921
30- let countryCode : string | undefined = currentLocale ?. split ( '-' ) [ 1 ] . toUpperCase ( ) ;
22+ // For currency other than EUR, we need to determine the country code from currency code
23+ // If currency is EUR, we use the locale to determine the country code
24+ let countryCode : string | undefined ;
25+ if ( currency !== 'EUR' ) {
26+ countryCode = currency . substring ( 0 , 2 ) ;
27+ } else {
28+ countryCode = currentLocale ?. split ( '-' ) [ 1 ] . toUpperCase ( ) ;
29+ }
3130
3231 // If countryCode is still undefined, setting it as US
3332 if ( ! countryCode ) {
@@ -67,11 +66,7 @@ export default {
6766 Currency : ( value , options ) => CurrencyFormatter ( value , options ) ,
6867 'Currency-Code' : ( value , options ) => CurrencyFormatter ( value , { ...options , symbol : false } ) ,
6968 Decimal : ( value , options ) => NumberFormatter ( value , options ) ,
70- 'Decimal-Auto' : ( value , options ) =>
71- NumberFormatter ( value , {
72- ...options ,
73- decPlaces : Number . isInteger ( value ) ? 0 : 2
74- } ) ,
69+ 'Decimal-Auto' : ( value , options ) => NumberFormatter ( value , { ...options , decPlaces : Number . isInteger ( value ) ? 0 : 2 } ) ,
7570 Integer : ( value , options ) => NumberFormatter ( value , { ...options , decPlaces : 0 } ) ,
7671 Percentage : ( value , options ) => SymbolFormatter ( value , { ...options , symbol : '%' } )
7772} ;
0 commit comments