Public
Edited
Apr 18, 2023
1 fork
Importers
1 star
Insert cell
Insert cell
// e.g. 10394879 -> 10MB
bytesToString = function (bytes) {
let format = d3.format(".0f");

if (bytes < 1024) {
return format(bytes) + "B";
} else if (bytes < 1024 * 1024) {
return format(bytes / 1024) + "kB";
} else if (bytes < 1024 * 1024 * 1024) {
return format(bytes / 1024 / 1024) + "MB";
} else if (bytes < 1024 * 1024 * 1024 * 1024) {
return format(bytes / 1024 / 1024 / 1024) + "GB";
} else if (bytes < 1024 * 1024 * 1024 * 1024 * 1024) {
return format(bytes / 1024 / 1024 / 1024 / 1024) + "TB";
} else {
return (
d3.format(",")(format(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