From 9b55010915be57bde1e8ed649e2d3dea1affcaba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint?= Date: Wed, 28 Jul 2021 20:02:17 +0200 Subject: [PATCH] *** Version 2 *** Created a method in NumberUtils.kt which formats the displaying number. This method groups the numbers by thousands with space separator. --- app/src/main/java/awais/instagrabber/utils/NumberUtils.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/awais/instagrabber/utils/NumberUtils.kt b/app/src/main/java/awais/instagrabber/utils/NumberUtils.kt index ab475350..e868b93c 100644 --- a/app/src/main/java/awais/instagrabber/utils/NumberUtils.kt +++ b/app/src/main/java/awais/instagrabber/utils/NumberUtils.kt @@ -2,6 +2,7 @@ package awais.instagrabber.utils +import java.text.DecimalFormat import java.util.* import kotlin.math.ln import kotlin.math.pow @@ -69,11 +70,12 @@ fun abbreviate(number: Long, options: AbbreviateOptions? = null): String { // adapted from https://stackoverflow.com/a/9769590/1436766 var threshold = 1000 var addSpace = false + var decimalFormat = DecimalFormat("###,###") if (options != null) { threshold = options.threshold addSpace = options.addSpaceBeforePrefix } - if (number < threshold) return "" + number + if (number < threshold) return "" + decimalFormat.format(number) val exp = (ln(number.toDouble()) / ln(threshold.toDouble())).toInt() return String.format( Locale.US,