Console: Fix number formatting (tickets #1912, #1913, #2126)

This commit is contained in:
zzz
2018-02-01 14:37:11 +00:00
parent 81713a0cab
commit a021e0d31f
15 changed files with 168 additions and 79 deletions

View File

@ -684,10 +684,10 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
StringBuilder buf = new StringBuilder(256);
buf.append("<br><hr class=\"debug\"><b>DHT DEBUG</b><br><hr class=\"debug\"><hr><b>TX:</b> ").append(_txPkts.get()).append(" pkts / ")
.append(DataHelper.formatSize2(_txBytes.get())).append("B / ")
.append(DataHelper.formatSize2(_txBytes.get() * 1000 / uptime)).append("Bps<br>" +
.append(DataHelper.formatSize2Decimal(_txBytes.get() * 1000 / uptime)).append("Bps<br>" +
"<b>RX:</b> ").append(_rxPkts.get()).append(" pkts / ")
.append(DataHelper.formatSize2(_rxBytes.get())).append("B / ")
.append(DataHelper.formatSize2(_rxBytes.get() * 1000 / uptime)).append("Bps<br>" +
.append(DataHelper.formatSize2Decimal(_rxBytes.get() * 1000 / uptime)).append("Bps<br>" +
"<b>DHT Peers:</b> ").append( _knownNodes.size()).append("<br>" +
"<b>Blacklisted:</b> ").append(_blacklist.size()).append("<br>" +
"<b>Sent tokens:</b> ").append(_outgoingTokens.size()).append("<br>" +

View File

@ -1754,7 +1754,7 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("<div class=\"percentBarOuter\">");
out.write("<div class=\"percentBarInner\" style=\"width: " + percent + "%;\">");
out.write("<div class=\"percentBarText\" tabindex=\"0\" title=\"");
out.write(percent + "% " + _t("complete") + " - " + DataHelper.formatSize2(remaining) + "B " + _t("remaining"));
out.write(percent + "% " + _t("complete") + "; " + DataHelper.formatSize2(remaining) + "B " + _t("remaining"));
out.write("\">");
out.write(formatSize(total-remaining) + thinsp(noThinsp) + formatSize(total));
out.write("</div></div></div>");
@ -2752,18 +2752,8 @@ public class I2PSnarkServlet extends BasicServlet {
return null;
}
// rounding makes us look faster :)
private static String formatSize(long bytes) {
if (bytes < 5000)
// replace &nbsp; with narrow non-breaking space (&#8239;)
return bytes + "&#8239;B";
else if (bytes < 5*1024*1024)
return ((bytes + 512)/1024) + "&#8239;KB";
else if (bytes < 10*1024*1024*1024l)
return ((bytes + 512*1024)/(1024*1024)) + "&#8239;MB";
else
return ((bytes + 512*1024*1024)/(1024*1024*1024)) + "&#8239;GB";
return DataHelper.formatSize2(bytes) + 'B';
}
/**