diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-06-11 06:08:44 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-06-11 06:08:44 +0900 |
| commit | 7c86b866bff9b604ee84194872ee04e3470f1281 (patch) | |
| tree | 5121a9c5aa906defe45dddbef0c080068c3b99b0 /src/web/app/common/scripts | |
| parent | [Client] Improve graph rendering of the server home widget (diff) | |
| download | sharkey-7c86b866bff9b604ee84194872ee04e3470f1281.tar.gz sharkey-7c86b866bff9b604ee84194872ee04e3470f1281.tar.bz2 sharkey-7c86b866bff9b604ee84194872ee04e3470f1281.zip | |
[Client] Improve bytes-to-size function
Add the digits argument
Diffstat (limited to 'src/web/app/common/scripts')
| -rw-r--r-- | src/web/app/common/scripts/bytes-to-size.js | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/web/app/common/scripts/bytes-to-size.js b/src/web/app/common/scripts/bytes-to-size.js index e143387141..af0268dbd0 100644 --- a/src/web/app/common/scripts/bytes-to-size.js +++ b/src/web/app/common/scripts/bytes-to-size.js @@ -1,6 +1,6 @@ -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]; }; |