2022-04-21 15:01:42 +00:00
|
|
|
export const pn = (value?: number | null): string | undefined => {
|
|
|
|
if (value === null || value === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-09 17:18:04 +00:00
|
|
|
const parts = value.toString().split('.');
|
2022-04-21 15:01:42 +00:00
|
|
|
|
2022-09-09 17:18:04 +00:00
|
|
|
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
2022-04-21 15:01:42 +00:00
|
|
|
|
2022-09-09 17:18:04 +00:00
|
|
|
return parts.join('.');
|
2022-04-21 15:01:42 +00:00
|
|
|
};
|
2022-08-30 18:49:16 +00:00
|
|
|
|
2022-09-09 17:18:04 +00:00
|
|
|
export const amountToString: (
|
|
|
|
amount: string,
|
|
|
|
has_range: boolean,
|
|
|
|
min_amount: number,
|
|
|
|
max_amount: number,
|
|
|
|
) => string = (amount, has_range, min_amount, max_amount) => {
|
|
|
|
if (has_range) {
|
|
|
|
return (
|
|
|
|
pn(parseFloat(Number(min_amount).toPrecision(4))) +
|
|
|
|
'-' +
|
|
|
|
pn(parseFloat(Number(max_amount).toPrecision(4)))
|
|
|
|
);
|
2022-08-30 18:49:16 +00:00
|
|
|
}
|
2022-09-09 17:18:04 +00:00
|
|
|
return pn(parseFloat(Number(amount).toPrecision(4))) || '';
|
|
|
|
};
|
2022-08-30 18:49:16 +00:00
|
|
|
|
2022-09-09 17:18:04 +00:00
|
|
|
export default pn;
|