mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
34 lines
566 B
JavaScript
34 lines
566 B
JavaScript
const priceFormatInfo = {
|
|
USD: {
|
|
prefix: '$',
|
|
suffix: 'USD',
|
|
},
|
|
CAD: {
|
|
prefix: '$',
|
|
suffix: 'CAD',
|
|
},
|
|
AUD: {
|
|
prefix: '$',
|
|
suffix: 'AUD',
|
|
},
|
|
EUR: {
|
|
prefix: '€',
|
|
suffix: '',
|
|
},
|
|
GPB: {
|
|
prefix: '£',
|
|
suffix: '',
|
|
},
|
|
};
|
|
|
|
export const formatPrice = ( value, currency ) => {
|
|
const currencyInfo = priceFormatInfo[ currency ];
|
|
const amount = value.toFixed( 2 );
|
|
|
|
if ( ! currencyInfo ) {
|
|
console.error( `Unsupported currency: ${ currency }` );
|
|
return amount;
|
|
}
|
|
|
|
return `${ currencyInfo.prefix }${ amount } ${ currencyInfo.suffix }`;
|
|
};
|