Less decimals

This commit is contained in:
Max Howell 2023-04-20 11:21:40 -04:00
parent 4d19688c87
commit 7bc8a958bb
No known key found for this signature in database
GPG key ID: 741BB84EF5BB9EEC

View file

@ -20,11 +20,14 @@
unit = "MB";
divisor = 1024 ** 2;
} else if (n > 1024) {
unit = "KB";
unit = "kB";
divisor = 1024;
}
return `${(n / divisor).toFixed(2)} ${unit}`;
const N = n / divisor;
const decimals = n < 10 ? 2 : 1; // its more informative to show more decimals but only for smaller numbers
return `${N.toFixed(decimals)} ${unit}`;
};
console.log(pkg);
</script>