StringUtils to/formatNumber: fix, step 1
authorNiki Roo <niki@nikiroo.be>
Sat, 13 Apr 2019 05:14:30 +0000 (07:14 +0200)
committerNiki Roo <niki@nikiroo.be>
Sat, 13 Apr 2019 05:14:30 +0000 (07:14 +0200)
src/be/nikiroo/utils/StringUtils.java
src/be/nikiroo/utils/test/StringUtilsTest.java

index 21261117f0205010c30016af01d4c14eface39d6..36fdfbe2c967359d0677c3935bd1c56b75346b44 100644 (file)
@@ -838,11 +838,14 @@ public class StringUtils {
                String deci = "";
 
                int deciDigits = 0;
-               if (value >= 1000000l) {
+               if (value >= 1000000000l) {
+                       deciDigits = (int) (value % 1000000000l);
+                       value = value / 1000000000l;
+                       suffix = "G";
+               } else if (value >= 1000000l) {
                        deciDigits = (int) (value % 1000000l);
                        value = value / 1000000l;
                        suffix = "M";
-
                } else if (value >= 1000l) {
                        deciDigits = (int) (value % 1000l);
                        value = value / 1000l;
index df2ed5fb9ddb49b2afd7dfa6133424f26fc9648c..d290ed4663dcea44292b19872d4c4f0c76945a26 100644 (file)
@@ -250,6 +250,7 @@ class StringUtilsTest extends TestLauncher {
                                assertEquals("263k", StringUtils.formatNumber(263012l));
                                assertEquals("42k", StringUtils.formatNumber(42012l));
                                assertEquals("12M", StringUtils.formatNumber(12012121l));
+                               assertEquals("7G", StringUtils.formatNumber(7364635928l));
                        }
                });
 
@@ -261,10 +262,12 @@ class StringUtilsTest extends TestLauncher {
                                assertEquals(42700000l, StringUtils.toNumber("42.7M"));
                                assertEquals(1220l, StringUtils.toNumber("1.22k"));
                                assertEquals(1432l, StringUtils.toNumber("1.432k"));
+                               assertEquals(6938l, StringUtils.toNumber("6.938k"));
                                assertEquals("1.3k", StringUtils.formatNumber(1300l, 1));
                                assertEquals("263.2020k", StringUtils.formatNumber(263202l, 4));
                                assertEquals("1.26k", StringUtils.formatNumber(1267l, 2));
                                assertEquals("42.7M", StringUtils.formatNumber(42712121l, 1));
+                               assertEquals("5.09M", StringUtils.formatNumber(5094837485l, 2));
                        }
                });
        }