Fix wrong(1024) divisor for 1000-based prefixes

This commit is contained in:
wodry 2021-03-15 15:14:54 +01:00
parent eceb3f7707
commit d09ebc4723
2 changed files with 11 additions and 11 deletions

View File

@ -759,14 +759,14 @@ QString formatNiceTimeOffset(qint64 secs)
QString formatBytes(uint64_t bytes) QString formatBytes(uint64_t bytes)
{ {
if(bytes < 1024) if (bytes < 1'000)
return QObject::tr("%1 B").arg(bytes); return QObject::tr("%1 B").arg(bytes);
if(bytes < 1024 * 1024) if (bytes < 1'000'000)
return QObject::tr("%1 KB").arg(bytes / 1024); return QObject::tr("%1 kB").arg(bytes / 1'000);
if(bytes < 1024 * 1024 * 1024) if (bytes < 1'000'000'000)
return QObject::tr("%1 MB").arg(bytes / 1024 / 1024); return QObject::tr("%1 MB").arg(bytes / 1'000'000);
return QObject::tr("%1 GB").arg(bytes / 1024 / 1024 / 1024); return QObject::tr("%1 GB").arg(bytes / 1'000'000'000);
} }
qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal minPointSize, qreal font_size) { qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal minPointSize, qreal font_size) {

View File

@ -79,7 +79,7 @@ void TrafficGraphWidget::paintEvent(QPaintEvent *)
int base = floor(log10(fMax)); int base = floor(log10(fMax));
float val = pow(10.0f, base); float val = pow(10.0f, base);
const QString units = tr("KB/s"); const QString units = tr("kB/s");
const float yMarginText = 2.0; const float yMarginText = 2.0;
// draw lines // draw lines
@ -128,10 +128,10 @@ void TrafficGraphWidget::updateRates()
quint64 bytesIn = clientModel->node().getTotalBytesRecv(), quint64 bytesIn = clientModel->node().getTotalBytesRecv(),
bytesOut = clientModel->node().getTotalBytesSent(); bytesOut = clientModel->node().getTotalBytesSent();
float inRate = (bytesIn - nLastBytesIn) / 1024.0f * 1000 / timer->interval(); float in_rate_kilobytes_per_sec = static_cast<float>(bytesIn - nLastBytesIn) / timer->interval();
float outRate = (bytesOut - nLastBytesOut) / 1024.0f * 1000 / timer->interval(); float out_rate_kilobytes_per_sec = static_cast<float>(bytesOut - nLastBytesOut) / timer->interval();
vSamplesIn.push_front(inRate); vSamplesIn.push_front(in_rate_kilobytes_per_sec);
vSamplesOut.push_front(outRate); vSamplesOut.push_front(out_rate_kilobytes_per_sec);
nLastBytesIn = bytesIn; nLastBytesIn = bytesIn;
nLastBytesOut = bytesOut; nLastBytesOut = bytesOut;