File size: 273 Bytes
a03b3ba
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
export function pretty_si(num: number): string {
	let units = ["", "k", "M", "G", "T", "P", "E", "Z"];
	let i = 0;
	while (num > 1000 && i < units.length - 1) {
		num /= 1000;
		i++;
	}
	let unit = units[i];
	return (Number.isInteger(num) ? num : num.toFixed(1)) + unit;
}