- Create resolvers for each type of charts which needs data transformation after the group by operation: Bar Chart, Line Chart and Pie Chart - Move all the utils to the backend and refactored some into services This allows all the computation to be done in the backend, improving performances in the frontend.
27 lines
635 B
TypeScript
27 lines
635 B
TypeScript
export const formatToShortNumber = (amount: number) => {
|
|
const sign = amount < 0 ? '-' : '';
|
|
const absoluteAmount = Math.abs(amount);
|
|
|
|
if (absoluteAmount < 1000) {
|
|
return sign + absoluteAmount.toFixed(1).replace(/\.?0+$/, '');
|
|
}
|
|
|
|
if (absoluteAmount < 1_000_000) {
|
|
return (
|
|
sign + (absoluteAmount / 1000).toFixed(1).replace(/\.?0+$/, '') + 'k'
|
|
);
|
|
}
|
|
|
|
if (absoluteAmount < 1_000_000_000) {
|
|
return (
|
|
sign + (absoluteAmount / 1_000_000).toFixed(1).replace(/\.?0+$/, '') + 'm'
|
|
);
|
|
}
|
|
|
|
return (
|
|
sign +
|
|
(absoluteAmount / 1_000_000_000).toFixed(1).replace(/\.?0+$/, '') +
|
|
'b'
|
|
);
|
|
};
|