From 8758aebb45238a0193b8d09b987b80ac3cdf0513 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Sat, 13 Apr 2019 07:14:30 +0200 Subject: [PATCH] StringUtils to/formatNumber: fix, step 1 --- src/be/nikiroo/utils/StringUtils.java | 7 +++++-- src/be/nikiroo/utils/test/StringUtilsTest.java | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/be/nikiroo/utils/StringUtils.java b/src/be/nikiroo/utils/StringUtils.java index 2126111..36fdfbe 100644 --- a/src/be/nikiroo/utils/StringUtils.java +++ b/src/be/nikiroo/utils/StringUtils.java @@ -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; diff --git a/src/be/nikiroo/utils/test/StringUtilsTest.java b/src/be/nikiroo/utils/test/StringUtilsTest.java index df2ed5f..d290ed4 100644 --- a/src/be/nikiroo/utils/test/StringUtilsTest.java +++ b/src/be/nikiroo/utils/test/StringUtilsTest.java @@ -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)); } }); } -- 2.27.0