Public
Edited
Jun 4
1 fork
Importers
1 star
Insert cell
Insert cell
// e.g. 10394879 -> 10MB
bytesToString = function (bytes) {
let format0 = d3.format(".0f");
let format1 = d3.format(".1f");

if (bytes < 1024) {
return format0(bytes) + "B";
} else if (bytes < 1024 * 1024) {
return format0(bytes / 1024) + "kB";
} else if (bytes < 1024 * 1024 * 1024) {
return format1(bytes / 1024 / 1024) + "MB";
} else if (bytes < 1024 * 1024 * 1024 * 1024) {
return format1(bytes / 1024 / 1024 / 1024) + "GB";
} else if (bytes < 1024 * 1024 * 1024 * 1024 * 1024) {
return format1(bytes / 1024 / 1024 / 1024 / 1024) + "TB";
} else {
return format1(bytes / 1024 / 1024 / 1024 / 1024 / 1024) + "PB";
}
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more