Skip to content

Commit

Permalink
Fix wrong(1024) divisor for 1000-based prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wodry committed Mar 19, 2021
1 parent eceb3f7 commit 200b503
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,14 +759,14 @@ QString formatNiceTimeOffset(qint64 secs)

QString formatBytes(uint64_t bytes)
{
if(bytes < 1024)
if(bytes < 1000)
return QObject::tr("%1 B").arg(bytes);
if(bytes < 1024 * 1024)
return QObject::tr("%1 KB").arg(bytes / 1024);
if(bytes < 1024 * 1024 * 1024)
return QObject::tr("%1 MB").arg(bytes / 1024 / 1024);
if(bytes < 1000 * 1000)
return QObject::tr("%1 kB").arg(bytes / 1000);
if(bytes < 1000 * 1000 * 1000)
return QObject::tr("%1 MB").arg(bytes / 1000 / 1000);

return QObject::tr("%1 GB").arg(bytes / 1024 / 1024 / 1024);
return QObject::tr("%1 GB").arg(bytes / 1000 / 1000 / 1000);
}

qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal minPointSize, qreal font_size) {
Expand Down
7 changes: 4 additions & 3 deletions src/qt/trafficgraphwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void TrafficGraphWidget::paintEvent(QPaintEvent *)
int base = floor(log10(fMax));
float val = pow(10.0f, base);

const QString units = tr("KB/s");
const QString units = tr("kB/s");
const float yMarginText = 2.0;

// draw lines
Expand Down Expand Up @@ -128,8 +128,9 @@ void TrafficGraphWidget::updateRates()

quint64 bytesIn = clientModel->node().getTotalBytesRecv(),
bytesOut = clientModel->node().getTotalBytesSent();
float inRate = (bytesIn - nLastBytesIn) / 1024.0f * 1000 / timer->interval();
float outRate = (bytesOut - nLastBytesOut) / 1024.0f * 1000 / timer->interval();
// Rates are in bytes/millisecond which is equal to kilobytes/second
float inRate = (bytesIn - nLastBytesIn) * 1.0f / timer->interval();
float outRate = (bytesOut - nLastBytesOut) * 1.0f / timer->interval();
vSamplesIn.push_front(inRate);
vSamplesOut.push_front(outRate);
nLastBytesIn = bytesIn;
Expand Down

0 comments on commit 200b503

Please sign in to comment.