diff --git a/src/utils/formatting.js b/src/utils/formatting.js
index b1400d1..a40376a 100644
--- a/src/utils/formatting.js
+++ b/src/utils/formatting.js
@@ -148,3 +148,21 @@ export const testRegex = (value, regexString) => {
const regex = new RegExp(regexString);
return regex.test(value);
};
+
+export const numberToCompact = (num, digits) => {
+ const lookup = [
+ { value: 1, symbol: '' },
+ { value: 1e3, symbol: 'k' },
+ { value: 1e6, symbol: 'M' },
+ { value: 1e9, symbol: 'G' },
+ { value: 1e12, symbol: 'T' },
+ { value: 1e15, symbol: 'P' },
+ { value: 1e18, symbol: 'E' },
+ ];
+ const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
+ const item = lookup
+ .slice()
+ .reverse()
+ .find((i) => num >= i.value);
+ return item ? (num / item.value).toFixed(digits).replace(rx, '$1') + item.symbol : '0';
+};