Skip to content
Snippets Groups Projects
Commit 7c86b866 authored by syuilo's avatar syuilo
Browse files

[Client] Improve bytes-to-size function

Add the digits argument
parent 6c0c5fbe
No related branches found
No related tags found
No related merge requests found
export default bytes => {
export default (bytes, digits = 0) => {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return '0Byte';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.round(bytes / Math.pow(1024, i), 2) + sizes[i];
return (bytes / Math.pow(1024, i)).toFixed(digits).replace(/\.0+$/, '') + sizes[i];
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment