diff --git a/client/source/scripts/components/sidebar/SpeedLimitDropdown.js b/client/source/scripts/components/sidebar/SpeedLimitDropdown.js index 49dc2ced..5643fa01 100644 --- a/client/source/scripts/components/sidebar/SpeedLimitDropdown.js +++ b/client/source/scripts/components/sidebar/SpeedLimitDropdown.js @@ -67,7 +67,7 @@ class SpeedLimitDropdown extends React.Component { if (bytes === 0) { return 'Unlimited'; } else { - let formattedData = format.data(bytes, '/s', 0); + let formattedData = format.data(bytes, '/s', 1, {padded: false}); return ( {formattedData.value} diff --git a/client/source/scripts/util/formatData.js b/client/source/scripts/util/formatData.js index 67f47eb7..0af70cfe 100644 --- a/client/source/scripts/util/formatData.js +++ b/client/source/scripts/util/formatData.js @@ -68,7 +68,7 @@ const format = { } }, - data: (bytes, extraUnits, precision = 2) => { + data: (bytes, extraUnits, precision = 2, options = {}) => { let kilobyte = 1024, megabyte = kilobyte * 1024, gigabyte = megabyte * 1024, @@ -98,13 +98,20 @@ const format = { value = Number(value); if (!!value && value < 10) { - value = value.toFixed(precision); + value = Number(value.toFixed(precision)); } else if (!!value && value > 10 && value < 100) { - value = value.toFixed(precision - 1); + value = Number(value.toFixed(precision - 1)); } else if (!!value && value > 100) { value = Math.floor(value); } + if (options.padded === false) { + let decimal = value % 1; + if ((decimal < 0.1 && decimal >= 0) || (decimal > -0.1 && decimal <= 0)) { + value = value.toFixed(0); + } + } + if (extraUnits) { unit += extraUnits; }