You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
12 lines
403 B
12 lines
403 B
const formatUnits = (originalValue, singleUnit) => ['', 'K', 'M', 'G', 'T', 'P'].reduce((previous, unit, exponent) => {
|
|
const devisor = (1000 ** exponent);
|
|
if (originalValue > devisor) {
|
|
let value = originalValue / devisor;
|
|
value = value < 10 ? value.toFixed(2) : Math.floor(value);
|
|
return `${value.toLocaleString()} ${unit}${singleUnit}`;
|
|
}
|
|
|
|
return previous;
|
|
});
|
|
|
|
export default formatUnits;
|
|
|