22
common/resources/client/i18n/formatted-currency.tsx
Executable file
22
common/resources/client/i18n/formatted-currency.tsx
Executable file
@@ -0,0 +1,22 @@
|
||||
import {Fragment, memo} from 'react';
|
||||
import {useNumberFormatter} from './use-number-formatter';
|
||||
|
||||
interface FormattedCurrencyProps {
|
||||
value: number;
|
||||
currency: string;
|
||||
}
|
||||
export const FormattedCurrency = memo(
|
||||
({value, currency}: FormattedCurrencyProps) => {
|
||||
const formatter = useNumberFormatter({
|
||||
style: 'currency',
|
||||
currency,
|
||||
currencyDisplay: 'narrowSymbol',
|
||||
});
|
||||
|
||||
if (isNaN(value)) {
|
||||
value = 0;
|
||||
}
|
||||
|
||||
return <Fragment>{formatter.format(value)}</Fragment>;
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user