diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-04-19 08:07:04 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-04-19 08:07:04 -0500 |
| commit | c11c6f1a8b741bcb796c47716828ec7aec893714 (patch) | |
| tree | b7ccd6a1df5c8ad9c850310d329f47afcd01a091 /src | |
| parent | 7b007dd5288fb902638b5ff45d92d07421c34c54 (diff) | |
| download | slskd-c11c6f1a8b741bcb796c47716828ec7aec893714.tar.gz | |
include 2 decimal places, except for KB
Diffstat (limited to 'src')
| -rw-r--r-- | src/web/src/components/Transfers/TransferList.js | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/web/src/components/Transfers/TransferList.js b/src/web/src/components/Transfers/TransferList.js index 78e2e031..94b4b050 100644 --- a/src/web/src/components/Transfers/TransferList.js +++ b/src/web/src/components/Transfers/TransferList.js @@ -40,9 +40,20 @@ const formatBytesTransferred = ({ transferred, size }) => { const [t, tExt] = formatBytes(transferred).split(' ') const [s, sExt] = formatBytes(size).split(' ') - // include the size label for transferred if it differs from size - // e.g. 12 KB/3 MB => 2.9/3 MB - return `${t}${tExt === sExt ? '' : ' ' + tExt}/${s} ${sExt}` + const fmt = (n) => parseFloat(n).toFixed(2); + + // if less than 1 MB has been transferred, don't include decimals + if (tExt === 'KB') { + return `${t} KB/${fmt(s)} ${sExt}` + } + + // if the suffix for size and transferred doesn't match, include + // the suffix for each + if (tExt !== sExt) { + return `${fmt(t)} ${tExt}/${fmt(s)} ${sExt}` + } + + return `${fmt(t)}/${fmt(s)} ${sExt}` } class TransferList extends Component { |
