From f13f4fcb6e78eaa048df236e80f183b9cb2f62d3 Mon Sep 17 00:00:00 2001 From: zzz Date: Sun, 11 Feb 2018 20:59:58 +0000 Subject: [PATCH] Util: Number formatting tweaks (ticket #1913) --- core/java/src/net/i2p/data/DataHelper.java | 20 ++++++++++++++++--- history.txt | 14 +++++++++++++ .../src/net/i2p/router/RouterVersion.java | 2 +- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/core/java/src/net/i2p/data/DataHelper.java b/core/java/src/net/i2p/data/DataHelper.java index 128368c6e2..0cf7adbba1 100644 --- a/core/java/src/net/i2p/data/DataHelper.java +++ b/core/java/src/net/i2p/data/DataHelper.java @@ -1555,7 +1555,7 @@ public class DataHelper { case 6: return str + "Ei"; case 7: return str + "Zi"; case 8: return str + "Yi"; - default: return bytes + ""; + default: return Long.toString(bytes); } } @@ -1589,6 +1589,9 @@ public class DataHelper { * @since 0.9.31 */ public static String formatSize2(long bytes, boolean nonBreaking) { + String space = nonBreaking ? " " : " "; + if (bytes < 1024) + return bytes + space; double val = bytes; int scale = 0; while (val >= 1024) { @@ -1597,10 +1600,14 @@ public class DataHelper { } DecimalFormat fmt = new DecimalFormat("##0.00"); + if (val >= 200) { + fmt.setMaximumFractionDigits(0); + } else if (val >= 20) { + fmt.setMaximumFractionDigits(1); + } // Replace   with thin non-breaking space   (more consistent/predictable width between fonts & point sizes) - String space = nonBreaking ? " " : " "; String str = fmt.format(val) + space; switch (scale) { case 1: return str + "Ki"; @@ -1643,6 +1650,9 @@ public class DataHelper { * @since 0.9.34 */ public static String formatSize2Decimal(long bytes, boolean nonBreaking) { + String space = nonBreaking ? " " : " "; + if (bytes < 1000) + return bytes + space; double val = bytes; int scale = 0; while (val >= 1000) { @@ -1650,7 +1660,11 @@ public class DataHelper { val /= 1000; } DecimalFormat fmt = new DecimalFormat("##0.00"); - String space = nonBreaking ? " " : " "; + if (val >= 200) { + fmt.setMaximumFractionDigits(0); + } else if (val >= 20) { + fmt.setMaximumFractionDigits(1); + } String str = fmt.format(val) + space; switch (scale) { case 1: return str + "K"; diff --git a/history.txt b/history.txt index 09f78fdb17..d4e1ad9694 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,17 @@ +2018-02-11 zzz + * Util: Number formatting tweaks (ticket #1913) + +2018-02-09 zzz + * SusiMail: + - Don't collapse spaces in email display (ticket #2156) + - Constant URL for attachments + - Fixes when no subject is present + - Filename encoding fixes + - Handle lower case in Q-P decode + - Don't show the no-charset warning + - Thread loading mail from disk + - More error handling fixes + 2018-02-08 zzz * SusiMail: - Error handling fixes diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 0725033fa6..f6e6df3a5c 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 3; + public final static long BUILD = 4; /** for example "-test" */ public final static String EXTRA = "";